QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#796013#9804. Guess the Polygonucup-team4435#RE 33ms3972kbC++2042.7kb2024-12-01 06:12:382024-12-01 06:12:40

Judging History

This is the latest submission verdict.

  • [2024-12-01 06:12:40]
  • Judged
  • Verdict: RE
  • Time: 33ms
  • Memory: 3972kb
  • [2024-12-01 06:12:38]
  • Submitted

answer

#line 1 "/home/andyli/OneDrive/lixiang/code/r.cpp"
#pragma GCC optimize("-Ofast")
// #define CHECK_EOF
// #define LX_DEBUG
#line 2 "/home/andyli/lib/all.hpp"
#if defined(LX_LOCAL) && !defined(CPH)
#include <timer.hpp>
#endif
#line 2 "/home/andyli/lib/types.hpp"
#include <bits/stdc++.h>

using u8 = unsigned char;
using u16 = unsigned short;
using u32 = unsigned int;
using u64 = unsigned long long;
using u128 = unsigned __int128;
using usize = std::uintptr_t;
using isize = std::intptr_t;
using i8 = signed char;
using i16 = short;
using i32 = int;
using i64 = long long;
using i128 = __int128;
using f64 = double;
using ld = long double;
#define vc std::vector
template <typename T>
using vvc = vc<vc<T>>;
template <typename T>
using vvvc = vc<vvc<T>>;
using vi = vc<int>;
using vvi = vc<vi>;
using vvvi = vc<vvi>;
using pi = std::pair<int, int>;
using str = std::string;
template <typename T>
using PQ = std::priority_queue<T>;
template <typename T>
using PQG = std::priority_queue<T, vc<T>, std::greater<>>;
template <typename T>
struct make_unsigned: public std::make_unsigned<T> {};
template <>
struct make_unsigned<i128> {
    using type = u128;
};
template <typename T>
using make_unsigned_t = make_unsigned<T>::type;
template <typename T>
struct make_signed: public std::make_signed<T> {};
template <>
struct make_signed<u128> {
    using type = i128;
};
template <typename T>
using make_signed_t = make_signed<T>::type;
template <typename T>
concept tupleLike = requires { typename std::tuple_element_t<0, std::decay_t<T>>; } && !requires (T t) { t[0]; };
template <typename T>
concept Signed = std::signed_integral<T> || std::is_same_v<T, i128>;
template <typename T>
concept Unsigned = std::unsigned_integral<T> || std::is_same_v<T, u128>;
template <typename T>
concept Integer = Signed<T> || Unsigned<T>;
template <typename T>
concept Modint = requires { T::mod(); };
template <typename T>
concept StaticModint = requires { typename std::integral_constant<decltype(T::mod()), T::mod()>; };
#line 3 "/home/andyli/lib/template.hpp"
using namespace std::ranges;
using namespace std::literals;

// NOLINTBEGIN
#define FOR1(a) for (std::decay_t<decltype(a)> _ = 0; _ < (a); _++)
#define FOR2(i, a) for (std::decay_t<decltype(a)> i = 0; i < (a); i++)
#define FOR3(i, a, b) for (auto i = (a); i < (b); i++)
#define FOR4(i, a, b, c) for (auto i = (a); i < (b); i += (c))
#define FOR1_R(a) FOR2_R(i, a)
#define FOR2_R(i, a) for (auto i = (a); i--;)
#define FOR3_R(i, a, b) for (auto i = (b); i-- > (a);)
#define overload4(a, b, c, d, e, ...) e
#define overload3(a, b, c, d, ...) d
#define _for(...) overload4(__VA_ARGS__, FOR4, FOR3, FOR2, FOR1)(__VA_ARGS__)
#define _for_r(...) overload3(__VA_ARGS__, FOR3_R, FOR2_R, FOR1_R)(__VA_ARGS__)
#define foreach(x, a) for (auto&& x: a)
#define loop while (true)
[[maybe_unused]] struct {
    constexpr auto operator->*(auto&& f) const { return f(); }
} blk;
#define BLK blk->*[&]
#define lowbit(x) ((x) & (-(x)))
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define LB(c, x) distance(begin(c), lower_bound(c, x))
#define UB(c, x) distance(begin(c), upper_bound(c, x))
#define UNIQUE(c) sort(c), (c).erase(std::unique(all(c)), end(c))
#define VEC(type, a, ...) auto a = vec<type>(__VA_ARGS__)
#define VECI(a, ...) auto a = veci(__VA_ARGS__)
#define FORWARD(x) std::forward<decltype(x)>(x)
#define eb emplace_back
#if defined(LX_LOCAL) || defined(ASSERTIONS)
#define ASSERT(...) assert(__VA_ARGS__)
#else
#define ASSERT(...) void()
#endif
// NOLINTEND

constexpr auto floor(auto&& x, auto&& y) { return x / y - (x % y && (x ^ y) < 0); }
constexpr auto ceil(auto&& x, auto&& y) { return floor(x + y - 1, y); }
constexpr auto divmod(auto x, auto y) {
    auto&& q = floor(x, y);
    return std::pair{q, x - q * y};
}
constexpr u64 ten(int t) { return t == 0 ? 1 : ten(t - 1) * 10; }
constexpr int get_lg(auto n) { return n <= 1 ? 1 : std::__bit_width(n - 1); }
constexpr auto Max(const auto& x) { return x; }
constexpr auto Min(const auto& x) { return x; }
constexpr auto Max(const auto& x, const auto& y, const auto&... arg) { return x < y ? Max(y, arg...) : Max(x, arg...); }
constexpr auto Min(const auto& x, const auto& y, const auto&... arg) { return x < y ? Min(x, arg...) : Min(y, arg...); }
constexpr bool chkmax(auto& d, const auto&... x) {
    auto t = Max(x...);
    return t > d ? d = t, true : false;
}
constexpr bool chkmin(auto& d, const auto&... x) {
    auto t = Min(x...);
    return t < d ? d = t, true : false;
}
constexpr auto sum(input_range auto&& r) { return std::accumulate(all(r), range_value_t<decltype(r)>{}); }
constexpr auto sum(input_range auto&& r, auto init) { return std::accumulate(all(r), init); }
constexpr int len(auto&& x) { return size(x); }
template <typename T>
auto cumsum(const vc<T>& a) {
    int n = len(a);
    vc<T> b(n + 1);
    _for (i, n)
        b[i + 1] = b[i] + a[i];
    return b;
}
template <typename T>
auto cumsum(auto&& a) {
    int n = len(a);
    vc<T> b(n + 1);
    _for (i, n)
        b[i + 1] = b[i] + a[i];
    return b;
}
template <typename T>
auto vec(usize n, auto&&... s) {
    if constexpr (!sizeof...(s))
        return vc<T>(n);
    else
        return vc(n, vec<T>(s...));
}
auto veci(usize n, auto&&... s) {
    if constexpr (sizeof...(s) == 1)
        return vc(n, s...);
    else
        return vc(n, veci(s...));
}
template <typename T>
vi argsort(const vc<T>& a) {
    vi p(len(a));
    iota(all(p), 0);
    sort(p, [&](int i, int j) { return std::pair{a[i], i} < std::pair{a[j], j}; });
    return p;
}
vi sshift(const str& s, char c = 'a') {
    vi a(len(s));
    _for (i, len(s))
        a[i] = s[i] - c;
    return a;
}
template <typename T>
T pop(vc<T>& q) {
    T r = std::move(q.back());
    q.pop_back();
    return r;
}
template <typename T>
T pop(std::deque<T>& q) {
    T r = std::move(q.front());
    q.pop_front();
    return r;
}
template <typename T, typename S, typename C>
T pop(std::priority_queue<T, S, C>& q) {
    T r = q.top();
    q.pop();
    return r;
}
template <typename T>
constexpr T inf = std::numeric_limits<T>::max() * 0.49;
template <>
constexpr f64 inf<f64> = inf<i64>;
template <>
constexpr ld inf<ld> = inf<i64>;
#line 3 "/home/andyli/lib/utility/itos_table.hpp"

constexpr auto itos_table = [] {
    std::array<u32, 10000> O{};
    int x = 0;
    _for (i, 10)
        _for (j, 10)
            _for (k, 10)
                _for (l, 10)
                    O[x++] = i + j * 0x100 + k * 0x10000 + l * 0x1000000 + 0x30303030;
    return O;
}();
#line 3 "/home/andyli/lib/io.hpp"

#define FASTIO
#ifdef CHECK_EOF
#define ECHK0 *ip ? *ip++ : 0
#define ECHK1     \
    if (ch == EV) \
        return set(false), *this;
#define ECHK2 \
    if (!*ip) \
        return set(false), *this;
#define ECHK3 &&ch != -1
#define ECHK4 &&*ip
#define ECHK5     \
    if (ch == -1) \
        return set(false);
#define ECHK6 \
    if (!*ip) \
        return set(false);
#else
#define ECHK0 *ip++
#define ECHK1
#define ECHK2
#define ECHK3
#define ECHK4
#define ECHK5
#define ECHK6
#endif

#if defined(__unix__) && !defined(LX_DEBUG) && !defined(LX_LOCAL)
#define USE_MMAP
#define EV 0
#include <sys/mman.h>
#include <sys/stat.h>
#else
#define EV (-1)
#endif

struct IO {
    static constexpr usize bufSize = 1 << 20;
    static constexpr bool isdigit(int c) { return '0' <= c && c <= '9'; }
    static constexpr bool blank(int c) { return c <= ' '; }

    u32 prec = 12;
    FILE *in, *out;
    bool status;
#ifndef LX_DEBUG
    char obuf[bufSize], *ip, *op = obuf;
#ifndef USE_MMAP
    char ibuf[bufSize], *eip;
#endif
#endif

#ifdef LX_DEBUG
    int getch() { return fgetc(in); }
    int getch_unchecked() { return getch(); }
    int unget(int c = -1) { return ungetc(c, in); }
    int peek() { return unget(getch()); }
    void input(FILE* f) { in = f, set(); }
    void skipws() {
        int ch = getch();
        while (blank(ch) ECHK3)
            ch = getch();
        unget(ch);
    }
    void ireadstr(char* s, usize n) { fread(s, 1, n, in); }
#elif defined(USE_MMAP)
    void skipws() {
        while (blank(*ip) ECHK4)
            ip++;
        ECHK6
    }
    int unget(int = 0) = delete;
    int getch() { return ECHK0; }
    int getch_unchecked() { return *ip++; }
    int peek() { return *ip; }
    void input(FILE* f) {
        struct stat st;
        int fd;
        in = f;
        if (in)
            fd = fileno(in), fstat(fd, &st), ip = (char*)mmap(nullptr, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0), set();
    }
    void ireadstr(char* s, usize n) { memcpy(s, ip, n), ip += n; }
    static constexpr auto I = [] {
        std::array<u32, 0x10000> I{};
        fill(I, -1);
        _for (i, 10)
            _for (j, 10)
                I[i + j * 0x100 + 0x3030] = i * 10 + j;
        return I;
    }();
#else
    void skipws() {
        int ch = getch();
        while (blank(ch) ECHK3)
            ch = getch();
        ECHK5
        unget();
    }
    int unget(int = 0) { return *ip--; }
    int getch() { return (ip == eip ? (eip = (ip = ibuf) + fread(ibuf, 1, bufSize, in)) : nullptr), ip == eip ? -1 : *ip++; }
    int getch_unchecked() { return *ip++; }
    int peek() { return (ip == eip ? (eip = (ip = ibuf) + fread(ibuf, 1, bufSize, in)) : nullptr), ip == eip ? -1 : *ip; }
    void input(FILE* f) { in = f, ip = eip = ibuf, set(); }
    void ireadstr(char* s, usize n) {
        if (usize len = eip - ip; n > len) [[unlikely]] {
            memcpy(s, ip, len);
            n -= len;
            s += len;
            ip = eip;
            fread(s, 1, n, in);
        }
        else
            memcpy(s, ip, n), ip += n;
    }
#endif
    void input(std::string_view s) { input(fopen(s.data(), "rb")); }
    void set(bool s = true) { status = s; }
    IO(FILE* i = stdin, FILE* o = stdout) { input(i), output(o); }
    ~IO() { flush(); }
    template <typename... Args>
    requires (sizeof...(Args) > 1)
    IO& read(Args&... x) {
#ifdef CHECK_EOF
        (read(x) && ...);
#else
        (read(x), ...);
#endif
        return *this;
    }
    template <Signed T>
    IO& read(T& x) {
        x = 0;
        make_unsigned_t<T> t;
        bool sign = false;
#ifndef USE_MMAP
        int ch = getch();
        while (!isdigit(ch) ECHK3)
            sign = ch == '-', ch = getch();
        ECHK1
        t = 0;
        while (isdigit(ch))
            t = t * 10 + (ch ^ 48), ch = getch();
        unget(ch);
#else
        while (!isdigit(*ip) ECHK4)
            sign = *ip++ == '-';
        ECHK2
        t = *ip++ ^ 48;
        u16* tip = (u16*)ip;
        while (~I[*tip])
            t = t * 100 + I[*tip++];
        ip = (char*)tip;
        if (isdigit(*ip))
            t = t * 10 + (*ip++ ^ 48);
#endif
        x = sign ? -t : t;
        return *this;
    }
    IO& read(Unsigned auto& x) {
        x = 0;
#ifndef USE_MMAP
        int ch = getch();
        while (!isdigit(ch) ECHK3)
            ch = getch();
        ECHK1
        while (isdigit(ch))
            x = x * 10 + (ch ^ 48), ch = getch();
        unget(ch);
#else
        while (!isdigit(*ip) ECHK4)
            ip++;
        ECHK2
        x = *ip++ ^ 48;
        u16* tip = (u16*)ip;
        while (~I[*tip])
            x = x * 100 + I[*tip++];
        ip = (char*)tip;
        if (isdigit(*ip))
            x = x * 10 + (*ip++ ^ 48);
#endif
        return *this;
    }
    IO& read(std::floating_point auto& x) {
        static str s;
        if (read(s))
            std::from_chars(s.begin().base(), s.end().base(), x);
        return *this;
    }
    template <typename T = int>
    T read() {
        std::decay_t<T> x;
        return read(x), x;
    }
    IO& read(char& ch) {
        skipws();
        ch = getch();
        ECHK1
        return *this;
    }
#ifdef USE_MMAP
    usize next_size() const {
        char* ip = this->ip;
        while (!blank(*ip) ECHK4)
            ip++;
        return ip - this->ip;
    }
    IO& read(char* s) {
        skipws();
        auto n = next_size();
        ireadstr(s, n);
        s[n] = 0;
        return *this;
    }
    IO& read(str& s) {
        skipws();
        auto n = next_size();
        s.assign(ip, n);
        ip += n;
        return *this;
    }
    IO& readstr(str& s, usize n) {
        skipws();
        s.assign(ip, n);
        ip += n;
        return *this;
    }
#else
    IO& read(char* s) {
        skipws();
        int ch = peek();
        ECHK1
        while (!blank(ch))
            *s++ = ch, getch_unchecked(), ch = peek();
        *s = 0;
        return *this;
    }
    IO& read(str& s) {
        skipws();
        int ch = peek();
        ECHK1
        s.erase();
        while (!blank(ch))
            s.append(1, ch), getch_unchecked(), ch = peek();
        return *this;
    }
    IO& readstr(str& s, usize n) {
        skipws();
        s.resize(n);
        ireadstr(s.data(), n);
        return *this;
    }
#endif
    IO& readstr(char* s, usize n) {
        skipws();
        ireadstr(s, n);
        s[n] = 0;
        return *this;
    }
    IO& readline(char* s) {
        char* t = s;
        int ch = getch();
        while (ch != '\n' && ch != EV)
            *s++ = ch, ch = getch();
        *s = 0;
        if (s == t && ch == EV)
            set(false);
        return *this;
    }
    IO& readline(str& s) {
        s.erase();
        int ch = getch();
        while (ch != '\n' && ch != EV)
            s.append(1, ch), ch = getch();
        if (s.empty() && ch == EV)
            set(false);
        return *this;
    }
    IO& read(tupleLike auto& t) {
        return std::apply([&](auto&... t) { (read(t), ...); }, t), *this;
    }
    IO& read(forward_range auto&& r) { return readArray(FORWARD(r)); }
    template <typename T>
    requires requires (T t, IO& io) { t.read(io); }
    IO& read(T& t) { return t.read(*this), *this; }
    template <std::forward_iterator I>
    IO& readArray(I f, I l) {
        while (f != l)
            read(*f++);
        return *this;
    }
    IO& readArray(forward_range auto&& r) { return readArray(all(r)); }
    IO& zipread(auto&&... a) {
        _for (i, (len(a), ...))
            read(a[i]...);
        return *this;
    }

#ifdef LX_DEBUG
    void flush() { fflush(out), set(); }
    void putch_unchecked(char c) { fputc(c, out); }
    void putch(char c) { putch_unchecked(c); }
    void writestr(const char* s, usize n) { fwrite(s, 1, n, out); }
#else
    void flush() { fwrite(obuf, 1, op - obuf, out), op = obuf; }
    void putch_unchecked(char c) { *op++ = c; }
    void putch(char c) { (op == end(obuf) ? flush() : void()), putch_unchecked(c); }
    void writestr(const char* s, usize n) {
        if (n >= usize(end(obuf) - op)) [[unlikely]]
                    flush(), fwrite(s, 1, n, out);
        else
            memcpy(op, s, n), op += n;
    }
#endif
    void output(std::string_view s) { output(fopen(s.data(), "wb")); }
    void output(FILE* f) { out = f; }
    void setprec(u32 n = 6) { prec = n; }
    template <typename... Args>
    requires (sizeof...(Args) > 1)
    void write(Args&&... x) { (write(FORWARD(x)), ...); }
    void write() const {}
    template <Signed T>
    void write(T x) {
        make_unsigned_t<T> y = x;
        if (x < 0)
            putch('-'), write(y = -y);
        else
            write(y);
    }
    void write(std::unsigned_integral auto x) {
#ifndef LX_DEBUG
        if (end(obuf) - op < 64) [[unlikely]]
                    flush();

        auto L = [&](int x) { return x == 1 ? 0 : ten(x - 1); };
        auto R = [&](int x) { return ten(x) - 1; };

        auto&& O = itos_table;
#define de(t)                            \
    case L(t)... R(t):                   \
        *(u32*)op = O[x / ten((t) - 4)]; \
        op += 4;                         \
        x %= ten((t) - 4);               \
        [[fallthrough]]

        switch (u64(x)) {
            de(18);
            de(14);
            de(10);
            de(6);
            case L(2)... R(2):
                *(u32*)op = O[x * 100];
                op += 2;
                break;

            de(17);
            de(13);
            de(9);
            de(5);
            case L(1)... R(1):
                *op++ = x ^ 48;
                break;

            default:
                *(u32*)op = O[x / ten(16)];
                op += 4;
                x %= ten(16);
                [[fallthrough]];
            de(16);
            de(12);
            de(8);
            case L(4)... R(4):
                *(u32*)op = O[x];
                op += 4;
                break;

            de(19);
            de(15);
            de(11);
            de(7);
            case L(3)... R(3):
                *(u32*)op = O[x * 10];
                op += 3;
                break;
        }
#undef de
#else
        write(u128(x));
#endif
    }
    void write(u128 x) {
#ifndef LX_DEBUG
        if (end(obuf) - op < 64) [[unlikely]]
                    flush();
#endif
        static int s[40], t = 0;
        do
            s[t++] = x % 10, x /= 10;
        while (x);
        while (t)
            putch_unchecked(s[--t] ^ 48);
    }
    void write(char c) { putch(c); }
    void write(std::floating_point auto x) {
        static char buf[512];
        writestr(buf, std::to_chars(buf, buf + 512, x, std::chars_format::fixed, prec).ptr - buf);
    }
    void write(std::string_view s) { writestr(s.data(), s.size()); }
    template <typename I, typename T = std::iter_value_t<I>>
    static constexpr char default_delim = tupleLike<T> || (input_range<T> && !requires (range_value_t<T> x) { {x} -> std::same_as<char&>; }) ? '\n' : ' ';
    template <std::input_iterator I, std::sentinel_for<I> S>
    void print_range(I f, S l, char d = default_delim<I>) {
        if (f != l)
            for (write(*f++); f != l; write(*f++))
                putch(d);
    }
    template <tupleLike T>
    void write(T&& t) {
        [&]<auto... I>(std::index_sequence<I...>) {
            (..., (!I ? void() : putch(' '), write(std::get<I>(t))));
        }(std::make_index_sequence<std::tuple_size_v<std::decay_t<T>>>());
    }
    template <input_range R>
    requires (!std::same_as<range_value_t<R>, char>)
    void write(R&& r) { print_range(all(r)); }
    template <typename T>
    requires requires (T t, IO& io) { t.write(io); }
    void write(T&& t) { t.write(*this); }
    void writeln(auto&&... x) { write(FORWARD(x)...), print(); }
    void print() { putch('\n'); }
    void print(auto&& x, auto&&... y) {
        write(FORWARD(x));
        ((putch(' '), write(FORWARD(y))), ...);
        print();
    }
    template <std::input_iterator I, std::sentinel_for<I> S>
    void displayArray(I f, S l, char d = default_delim<I>) { print_range(f, l, d), print(); }
    template <input_range R>
    void displayArray(R&& r, char d = default_delim<iterator_t<R>>) { displayArray(all(r), d); }
    operator bool() const { return status; }
} io;
#ifdef LX_LOCAL
IO err(nullptr, stderr);
#define dbg(x) err.print(#x, '=', x)
#else
#define dbg(x) \
    do {       \
    } while (false)
#endif
#define dR(type, ...) \
    type __VA_ARGS__; \
    io.read(__VA_ARGS__)
#define dRV(type, a, ...)      \
    VEC(type, a, __VA_ARGS__); \
    io.read(a)
#define STR(s, n) \
    str s;        \
    io.readstr(s, n)
void multipleTests(auto&& f) {
    dR(u32, q);
    _for (q)
        f();
}
void writeln(auto&&... x) { io.writeln(FORWARD(x)...); }
void print(auto&&... x) { io.print(FORWARD(x)...); }
void YES(bool v = true) { io.write(v ? "YES\n" : "NO\n"); }
inline void NO(bool v = true) { YES(!v); }
void Yes(bool v = true) { io.write(v ? "Yes\n" : "No\n"); }
inline void No(bool v = true) { Yes(!v); }
#line 5 "/home/andyli/OneDrive/lixiang/code/r.cpp"

#line 3 "/home/andyli/lib/poly/fft.hpp"

namespace CFFT {
    template <typename T>
    struct Cp {
        T x{}, y{};
        Cp operator+(const Cp& c) const { return {x + c.x, y + c.y}; }
        Cp& operator+=(const Cp& c) { return *this = *this + c; }
        Cp operator-(const Cp& c) const { return {x - c.x, y - c.y}; }
        Cp& operator-=(const Cp& c) { return *this = *this - c; }
        Cp operator*(const Cp& c) const { return {x * c.x - y * c.y, x * c.y + y * c.x}; }
        Cp operator*=(const Cp& c) { return *this = *this * c; }
        Cp operator*(T z) const { return {x * z, y * z}; }
        Cp operator*=(T z) { return *this = *this * z; }
        Cp operator-() const { return {-x, -y}; }
        Cp conj() const { return {x, -y}; }
        Cp rotl() const { return {-y, x}; }
    };
    using C = Cp<f64>;
    vc<C> w;

    void setw(int k) {
        if (len(w) >= (1 << --k))
            return;
        w.resize(1 << k);
        w[0] = {1, 0};
        for (int i = 1; i < (1 << k); i <<= 1) {
            auto arg = std::numbers::pi / (i << 1);
            w[i] = {cos(arg), sin(arg)};
        }
        _for (i, 1, 1 << k)
            w[i] = w[i & (i - 1)] * w[lowbit(i)];
    }
    void fft(vc<C>& a, int k) {
        if (len(a) <= 1)
            return;
        if (k == 1) {
            a[0] += std::exchange(a[1], a[0] - a[1]);
            return;
        }
        if (k & 1) {
            int v = 1 << (k - 1);
            _for (j, v)
                a[j] += std::exchange(a[j + v], a[j] - a[j + v]);
        }
        int u = 1 << (k & 1), v = 1 << (k - 2 - (k & 1));
        C imag = w[1];
        while (v) {
            for (int j0 = 0, j1 = v, j2 = j1 + v, j3 = j2 + v; j0 < v; j0++, j1++, j2++, j3++) {
                C t0 = a[j0], t1 = a[j1], t2 = a[j2], t3 = a[j3];
                C t0p2 = t0 + t2, t1p3 = t1 + t3;
                C t0m2 = t0 - t2, t1m3 = (t1 - t3) * imag;
                a[j0] = t0p2 + t1p3, a[j1] = t0p2 - t1p3;
                a[j2] = t0m2 + t1m3, a[j3] = t0m2 - t1m3;
            }
            _for (jh, 1, u) {
                C ww = w[jh], xx = w[jh << 1], wx = ww * xx;
                for (int j0 = (jh * v) << 2, j1 = j0 + v, j2 = j1 + v, j3 = j2 + v, je = j1; j0 < je; j0++, j1++, j2++, j3++) {
                    C t0 = a[j0], t1 = a[j1] * xx, t2 = a[j2] * ww, t3 = a[j3] * wx;
                    C t0p2 = t0 + t2, t1p3 = t1 + t3;
                    C t0m2 = t0 - t2, t1m3 = (t1 - t3) * w[1];
                    a[j0] = t0p2 + t1p3, a[j1] = t0p2 - t1p3;
                    a[j2] = t0m2 + t1m3, a[j3] = t0m2 - t1m3;
                }
            }
            u <<= 2, v >>= 2;
        }
    }
    void ifft(vc<C>& a, int k) {
        if (len(a) <= 1)
            return;
        if (k == 1) {
            a[0] += std::exchange(a[1], a[0] - a[1]);
            return;
        }
        int u = 1 << (k - 2), v = 1;
        C imag = w[1].conj();
        while (u) {
            for (int j0 = 0, j1 = v, j2 = j1 + v, j3 = j2 + v; j0 < v; j0++, j1++, j2++, j3++) {
                C t0 = a[j0], t1 = a[j1], t2 = a[j2], t3 = a[j3];
                C t0p1 = t0 + t1, t2p3 = t2 + t3;
                C t0m1 = t0 - t1, t2m3 = (t2 - t3) * imag;
                a[j0] = t0p1 + t2p3, a[j2] = t0p1 - t2p3;
                a[j1] = t0m1 + t2m3, a[j3] = t0m1 - t2m3;
            }
            _for (jh, 1, u) {
                C ww = w[jh].conj(), xx = w[jh << 1].conj(), yy = w[(jh << 1) + 1].conj();
                for (int j0 = (jh * v) << 2, j1 = j0 + v, j2 = j1 + v, j3 = j2 + v, je = j1; j0 < je; j0++, j1++, j2++, j3++) {
                    C t0 = a[j0], t1 = a[j1], t2 = a[j2], t3 = a[j3];
                    C t0p1 = t0 + t1, t2p3 = t2 + t3;
                    C t0m1 = (t0 - t1) * xx, t2m3 = (t2 - t3) * yy;
                    a[j0] = t0p1 + t2p3, a[j2] = (t0p1 - t2p3) * ww;
                    a[j1] = t0m1 + t2m3, a[j3] = (t0m1 - t2m3) * ww;
                }
            }
            u >>= 2, v <<= 2;
        }
        if (k & 1) {
            u = 1 << (k - 1);
            _for (j, u)
                a[j] += std::exchange(a[j + u], a[j] - a[j + u]);
        }
    }
} // namespace CFFT
#line 3 "/home/andyli/lib/poly/convolution_naive.hpp"

template <typename T, typename U = T>
vc<U> convolution_naive(const vc<T>& a, const vc<T>& b) {
    int n = len(a), m = len(b);
    if (n > m)
        return convolution_naive<T, U>(b, a);
    if (!n)
        return {};
    vc<U> r(n + m - 1);
    _for (i, n)
        _for (j, m)
            r[i + j] += U(a[i]) * b[j];
    return r;
}
#line 8 "/home/andyli/OneDrive/lixiang/code/r.cpp"

// 0: neg = false, dat = {}
struct bigint {
    using M = bigint;

    static constexpr int logD = 7;
    static constexpr u32 D = 10000000, B = 1 << 14;
    bool neg = false;
    vi dat;

    bigint() = default;
    bigint(bool n, vi d): neg(n), dat(std::move(d)) {}

    template <Signed T>
    bigint(T x) {
        make_unsigned_t<T> y = x;
        if (x < 0)
            neg = true, y = -y;
        dat = _from_int(y);
    }
    template <Unsigned T>
    bigint(T x): dat(_from_int(x)) {}

    bigint(std::string_view s) {
        if (s == "0")
            return;
        if (s[0] == '-')
            s = s.substr(1), neg = true;
        for (int ie = len(s); 0 < ie; ie -= logD) {
            int is = max(0, ie - logD);
            int x = 0;
            _for (i, is, ie) {
                x = x * 10 + (s[i] >= 'A' ? s[i] - 'A' + 10 : s[i] - '0');
            }
            dat.eb(x);
        }
    }

    void ok_write() const {
        using namespace std;
        if (dat.empty()) {
            cout << "0";
            return;
        }
        if (neg)
            cout << "-";
        for (int i = dat.size(); i--;) {
            cout << _itos(dat[i], i != dat.size() - 1);
        }
    }

#ifdef FASTIO
    void read(IO& io) {
        static str s;
        io.read(s);
        *this = bigint(s);
    }
    void write(IO& io) const {
        if (dat.empty()) {
            io.putch('0');
            return;
        }
        if (neg)
            io.putch('-');
        _for_r (i, len(dat))
            io.write(_itos(dat[i], i != len(dat) - 1));
    }
#endif
    friend M operator+(const M& lhs, const M& rhs) {
        if (lhs.neg == rhs.neg)
            return {lhs.neg, _add(lhs.dat, rhs.dat)};
        if (_leq(lhs.dat, rhs.dat)) {
            auto c = _sub(rhs.dat, lhs.dat);
            bool n = rhs.neg && !c.empty();
            return {n, std::move(c)};
        }
        auto c = _sub(lhs.dat, rhs.dat);
        bool n = lhs.neg && !c.empty();
        return {n, std::move(c)};
    }
    friend M operator-(const M& lhs, const M& rhs) {
        if (rhs.dat.empty())
            return lhs;
        if (lhs.neg == !rhs.neg)
            return {lhs.neg, _add(lhs.dat, rhs.dat)};
        if (_leq(lhs.dat, rhs.dat)) {
            auto c = _sub(rhs.dat, lhs.dat);
            bool n = !rhs.neg && !c.empty();
            return {n, std::move(c)};
        }
        auto c = _sub(lhs.dat, rhs.dat);
        bool n = lhs.neg && !c.empty();
        return {n, std::move(c)};
    }

    friend M operator*(const M& lhs, const M& rhs) {
        auto c = _mul(lhs.dat, rhs.dat);
        bool n = (lhs.neg ^ rhs.neg) && !c.empty();
        return {n, std::move(c)};
    }
    friend auto divmod(const M& lhs, const M& rhs) {
        auto dm = _divmod_newton(lhs.dat, rhs.dat);
        bool dn = lhs.neg != rhs.neg && !dm.first.empty();
        bool mn = lhs.neg && !dm.second.empty();
        return std::pair{M{dn, std::move(dm.first)}, M{mn, std::move(dm.second)}};
    }
    friend M operator/(const M& lhs, const M& rhs) { return divmod(lhs, rhs).first; }
    friend M operator%(const M& lhs, const M& rhs) { return divmod(lhs, rhs).second; }

    M& operator+=(const M& rhs) { return *this = *this + rhs; }
    M& operator-=(const M& rhs) { return *this = *this - rhs; }
    M& operator*=(const M& rhs) { return *this = *this * rhs; }
    M& operator/=(const M& rhs) { return *this = *this / rhs; }
    M& operator%=(const M& rhs) { return *this = *this % rhs; }

    M& operator++() { return *this += 1; }
    M operator++(int) {
        M t = *this;
        ++*this;
        return t;
    }
    M& operator--() { return *this -= 1; }
    M operator--(int) {
        M t = *this;
        --*this;
        return t;
    }

    M operator-() const {
        if (dat.empty())
            return *this;
        return {!neg, dat};
    }
    M operator+() const { return *this; }
    friend M abs(const M& m) { return {false, m.dat}; }

    friend bool operator==(const M& lhs, const M& rhs) = default;
    friend bool operator<(const M& lhs, const M& rhs) { return lhs != rhs && _neq_lt(lhs, rhs); }
    friend bool operator<=(const M& lhs, const M& rhs) { return !(rhs < lhs); }
    friend bool operator>(const M& lhs, const M& rhs) { return rhs < lhs; }
    friend bool operator>=(const M& lhs, const M& rhs) { return !(lhs < rhs); }

    template <typename T>
    T to_int() const {
        T r = _to_int<T>(dat);
        return neg ? -r : r;
    }

private:
    static bool _lt(const vi& a, const vi& b) {
        if (len(a) != len(b))
            return len(a) < len(b);
        _for_r (i, len(a))
            if (a[i] != b[i])
                return a[i] < b[i];
        return false;
    }
    static bool _leq(const vi& a, const vi& b) { return a == b || _lt(a, b); }
    static bool _neq_lt(const M& lhs, const M& rhs) {
        if (lhs.neg != rhs.neg)
            return lhs.neg;
        return _lt(lhs.dat, rhs.dat) ^ lhs.neg;
    }
    static bool _is_one(const vi& a) { return len(a) == 1 && a[0] == 1; }
    static void _shrink(vi& a) {
        while (!a.empty() && !a.back())
            a.pop_back();
    }
    static vi _add(const vi& a, const vi& b) {
        vi c(max(len(a), len(b)) + 1);
        _for (i, max(len(a), len(b))) {
            if (i < len(a))
                c[i] += a[i];
            if (i < len(b))
                c[i] += b[i];
            if (c[i] >= D)
                c[i] -= D, c[i + 1]++;
        }
        _shrink(c);
        return c;
    }
    static vi _sub(vi a, const vi& b) {
        int t = 0;
        _for (i, len(a)) {
            if (i < len(b))
                t += b[i];
            a[i] -= t;
            t = 0;
            if (a[i] < 0)
                a[i] += D, t = 1;
        }
        _shrink(a);
        return a;
    }
    static vi _mul_naive(const vi& a, const vi& b) {
        auto c = convolution_naive<int, u64>(a, b);
        vi r(len(a) + len(b) + 2);
        u64 x = 0;
        _for (i, len(c)) {
            x += c[i];
            r[i] = x % D, x /= D;
        }
        int i = len(c);
        while (x)
            r[i++] = x % D, x /= D;
        _shrink(r);
        return r;
    }
    static vi _mul(const vi& a, const vi& b) {
        using namespace CFFT;
        if (a.empty() || b.empty())
            return {};
        if (_is_one(a))
            return b;
        if (_is_one(b))
            return a;
        int n = len(a), m = len(b);
        if (min(n, m) <= 30)
            return _mul_naive(a, b);
        int k = get_lg(n + m), sz = 1 << k;
        vc<C> c(sz), d(sz);
        _for (i, n)
            c[i] = {f64(a[i] % B), f64(a[i] / B)};
        _for (i, m)
            d[i] = {f64(b[i] % B), f64(b[i] / B)};
        setw(k);
        fft(c, k), fft(d, k);
        f64 fx = 1.0 / sz, fy = fx * 0.25;
        c[0] = {c[0].x * d[0].x + c[0].y * d[0].y, c[0].x * d[0].y + c[0].y * d[0].x};
        c[0] *= fx;
        c[1] *= d[1] * fx;
        for (int k = 2, m = 3; k < sz; k <<= 1, m <<= 1)
            for (int i = k, j = i + k - 1; i < m; i++, j--) {
                C oi = c[i] + c[j].conj(), hi = c[i] - c[j].conj();
                C oj = d[i] + d[j].conj(), hj = d[i] - d[j].conj();
                C r0 = oi * oj - hi * hj * ((i & 1) ? -w[i >> 1] : w[i >> 1]);
                C r1 = oj * hi + oi * hj;
                c[i] = (r0 + r1) * fy;
                c[j] = (r0 - r1).conj() * fy;
            }
        ifft(c, k);
        vi r(n + m + 2);
        u64 x = 0;
        _for (i, n + m) {
            x += i64(c[i].x + 0.5) + i64(c[i].y + 0.5) * B;
            r[i] = x % D, x /= D;
        }
        int i = n + m;
        while (x)
            r[i++] = x % D, x /= D;
        _shrink(r);
        return r;
    }
    static auto _divmod_li(const vi& a, const vi& b) {
        i64 va = _to_int<i64>(a), vb = b[0];
        return std::pair{_from_int(va / vb), _from_int(va % vb)};
    }
    static auto _divmod_i64(const vi& a, const vi& b) {
        i64 va = _to_int<i64>(a), vb = _to_int<i64>(b);
        return std::pair{_from_int(va / vb), _from_int(va % vb)};
    }
    static auto _divmod_1e8(const vi& a, const vi& b) {
        if (b[0] == 1)
            return std::pair{a, vi{}};
        if (len(a) <= 2)
            return _divmod_li(a, b);
        vi quo(len(a));
        i64 d = 0;
        int b0 = b[0];
        _for_r (i, len(a)) {
            d = d * D + a[i];
            int q = d / b0, r = d % b0;
            quo[i] = q, d = r;
        }
        _shrink(quo);
        return std::pair{std::move(quo), d ? vi{int(d)} : vi{}};
    }
    static auto _divmod_naive(const vi& a, const vi& b) {
        ASSERT(!b.empty());
        if (len(b) == 1)
            return _divmod_1e8(a, b);
        if (max(len(a), len(b)) <= 2)
            return _divmod_i64(a, b);
        if (_lt(a, b))
            return std::pair{vi{}, a};
        int norm = D / (b.back() + 1);
        vi x = _mul(a, {norm});
        vi y = _mul(b, {norm});
        int yb = y.back();
        vi quo(len(x) - len(y) + 1);
        vi rem(x.end() - len(y), x.end());
        _for_r (i, len(quo)) {
            if (len(rem) == len(y)) {
                if (_leq(y, rem))
                    quo[i] = 1, rem = _sub(rem, y);
            }
            else if (len(rem) > len(y)) {
                i64 rb = i64(rem[len(rem) - 1]) * D + rem[len(rem) - 2];
                int q = rb / yb;
                vi yq = _mul(y, {q});
                while (_lt(rem, yq))
                    q--, yq = _sub(yq, y);
                rem = _sub(rem, yq);
                while (_leq(y, rem))
                    q++, rem = _sub(rem, y);
                quo[i] = q;
            }
            if (i)
                rem.insert(rem.begin(), x[i - 1]);
        }
        _shrink(quo), _shrink(rem);
        auto [q2, r2] = _divmod_1e8(rem, {norm});
        return std::pair{std::move(quo), std::move(q2)};
    }
    static vi _calc_inv(const vi& a, int deg) {
        int k = deg, c = len(a);
        while (k > 64)
            k = (k + 1) >> 1;
        vi z(c + k + 1);
        z.back() = 1;
        z = _divmod_naive(z, a).first;
        while (k < deg) {
            vi s = _mul(z, z);
            s.insert(s.begin(), 0);
            int d = min(c, 2 * k + 1);
            vi t(a.end() - d, a.end()), u = _mul(s, t);
            u.erase(u.begin(), u.begin() + d);
            vi w(k + 1), w2 = _add(z, z);
            w.insert(w.end(), all(w2));
            z = _sub(w, u);
            z.erase(z.begin());
            k <<= 1;
        }
        z.erase(z.begin(), z.begin() + k - deg);
        return z;
    }
    static std::pair<vi, vi> _divmod_newton(const vi& a, const vi& b) {
        ASSERT(!b.empty());
        if (len(b) <= 64 || len(a) - len(b) <= 64)
            return _divmod_naive(a, b);
        int norm = D / (b.back() + 1);
        vi x = _mul(a, {norm}), y = _mul(b, {norm});
        int s = len(x), t = len(y);
        int deg = s - t + 2;
        vi z = _calc_inv(y, deg);
        vi q = _mul(x, z);
        q.erase(q.begin(), q.begin() + t + deg);
        vi yq = _mul(y, {q});
        while (_lt(x, yq))
            q = _sub(q, {1}), yq = _sub(yq, y);
        vi r = _sub(x, yq);
        while (_leq(y, r))
            q = _add(q, {1}), r = _sub(r, y);
        _shrink(q), _shrink(r);
        auto [q2, r2] = _divmod_1e8(r, {norm});
        return {std::move(q), std::move(q2)};
    }
    static str _itos(int x, bool zero_padding) {
        str r;
        _for (i, logD) {
            int t = x % 10;
            r += char(t < 10 ? '0' + t : 'A' + t - 10);
            x /= 10;
        }
        if (!zero_padding)
            while (!r.empty() && r.back() == '0')
                r.pop_back();
        reverse(r);
        return r;
    }
    static vi _from_int(Integer auto x) {
        vi r;
        while (x)
            r.eb(x % D), x /= D;
        return r;
    }
    template <typename T>
    static T _to_int(const vi& a) {
        T r{};
        _for_r (i, len(a))
            r = r * D + a[i];
        return r;
    }
};

bigint gcd(const bigint &a, const bigint &b) {
    if (b == bigint(0)) {
        return a;
    }
    return gcd(b, a % b);
}


template<class T>
class Frac {
public:
    T num;
    T den;
    void normalize() {
        bigint g = gcd(num, den);
        if (g < bigint(0)) {
            g = bigint(0) - g;
        }
        num /= g;
        den /= g;
    }

    Frac &operator+=(const Frac &rhs) {
        num = num * rhs.den + rhs.num * den;
        den *= rhs.den;
        return *this;
    }
    Frac &operator-=(const Frac &rhs) {
        num = num * rhs.den - rhs.num * den;
        den *= rhs.den;
        return *this;
    }
    Frac &operator*=(const Frac &rhs) {
        num *= rhs.num;
        den *= rhs.den;
        return *this;
    }
    Frac &operator/=(const Frac &rhs) {
        num *= rhs.den;
        den *= rhs.num;
        if (den < bigint(0)) {
            num = bigint(0) - num;
            den = bigint(0) - den;
        }
        return *this;
    }
    friend Frac operator+(Frac lhs, const Frac &rhs) {
        return lhs += rhs;
    }
    friend Frac operator-(Frac lhs, const Frac &rhs) {
        return lhs -= rhs;
    }
    friend Frac operator*(Frac lhs, const Frac &rhs) {
        return lhs *= rhs;
    }
    friend Frac operator/(Frac lhs, const Frac &rhs) {
        return lhs /= rhs;
    }
    friend Frac operator-(const Frac &a) {
        return Frac(bigint(0) - a.num, a.den);
    }
    friend bool operator==(const Frac &lhs, const Frac &rhs) {
        return lhs.num * rhs.den == rhs.num * lhs.den;
    }
    friend bool operator!=(const Frac &lhs, const Frac &rhs) {
        return lhs.num * rhs.den != rhs.num * lhs.den;
    }
    friend bool operator<(const Frac &lhs, const Frac &rhs) {
        return lhs.num * rhs.den < rhs.num * lhs.den;
    }
    friend bool operator>(const Frac &lhs, const Frac &rhs) {
        return lhs.num * rhs.den > rhs.num * lhs.den;
    }
    friend bool operator<=(const Frac &lhs, const Frac &rhs) {
        return lhs.num * rhs.den <= rhs.num * lhs.den;
    }
    friend bool operator>=(const Frac &lhs, const Frac &rhs) {
        return lhs.num * rhs.den >= rhs.num * lhs.den;
    }
};

using Fraction = Frac<bigint>;

Fraction ask(bigint p, bigint q) {
    q *= 4;
    using namespace std;
    cout << "? ";
    p.ok_write();
    cout << ' ';
    q.ok_write();
    cout << endl;
    string r, s;
    cin >> r >> s;
    return {bigint(r), bigint(s)};
    // bigint r, s; cin >> r >> s;
    // return {r, s};
    // dR(bigint, a, b);
    // return {a, b};
}


void solve() {
    using namespace std;
    using ll = long long;
    map<int, int> cnt;
    int n; cin >> n;
    // dR(int, n);
    for (int _ = 0; _ < n; _++) {
        // dR(int, x, y);
        int x, y;
        cin >> x >> y;
        x *= 4;
        cnt[x]++;
    }

    vector<pair<ll, ll>> a(cnt.begin(), cnt.end());
    if (a.size() <= 1) {
        cout << "! 0 1" << endl;
        // print("! 0 1");
        // io.flush();
        return;
    }

    Fraction result = {bigint(0), bigint(1)};
    vector<Fraction> to_sum;

    auto Add = [&] (Fraction len1, Fraction len2, Fraction xdiff, Fraction ladd, Fraction radd) {
        // assert(xdiff.num != bigint(0));
        Fraction L = len1;
        Fraction R = len2;
        if (ladd == radd) {
        } else if (ladd.num != bigint(0)) {
            auto df = len1 - len2;
            df /= xdiff;
            df *= (xdiff + ladd);
            L = df + len2;
        } else if (radd.num != bigint(0)) {
            auto df = len2 - len1;
            df /= xdiff;
            df *= (xdiff + radd);
            R = df + len1;
        } else {
            assert(0);
        }
        auto h = xdiff + ladd + radd;
        auto res = (L + R) * h;
        to_sum.push_back(res);
    };


    Fraction len1, ladd, prv;
    if (a[0].second == 1) {
        len1 = {bigint(0), bigint(1)};
        ladd = {bigint(0), bigint(1)};
        prv = {bigint(a[0].first), bigint(1)};
    } else {
        len1 = ask(bigint(a[0].first), bigint(1));
        ladd = {bigint(0), bigint(1)};
        prv = {bigint(a[0].first), bigint(1)};
    }

    for(int i = 1; i + 1 < (int)a.size(); ++i) {
        if (a[i].second == 1) {
            Fraction nx = {bigint(a[i].first), bigint(1)};
            Fraction cur = ask(bigint(a[i].first), bigint(1));

            Add(len1, cur, nx - prv, ladd, Fraction{bigint(0), bigint(1)});

            prv = nx;
            ladd = {bigint(0), bigint(1)};
            len1 = cur;
            continue;
        }
        Fraction radd = {bigint(1), bigint(1)};
        Fraction nx = {bigint(a[i].first), bigint(1)};
        Fraction rp = nx - radd;

        Fraction len2 = ask(rp.num, rp.den);

        Fraction xdiff = rp - prv;
        Add(len1, len2, xdiff, ladd, radd);

        prv = nx + radd;
        ladd = radd;
        len1 = ask(prv.num, prv.den);
    }
    {
        Fraction radd = {bigint(0), bigint(1)};
        Fraction nx = {a.back().first, 1};
        Fraction len2 = {bigint(0), bigint(1)};
        if (a.back().second > bigint(1)) {
            len2 = ask(nx.num, nx.den);
        }

        Add(len1, len2, nx - prv, ladd, radd);
    }

    auto rec = [&](auto &&self, int l, int r) -> Fraction {
        if (r - l == 1) {
            return to_sum[l];
        }
        int mid = (l + r) / 2;
        auto tot = self(self, l, mid) + self(self, mid, r);
        tot.normalize();
        return tot;
    };

    result = rec(rec, 0, to_sum.size());

    result.den *= bigint(8);
    result.normalize();
    cout << "! ";
    result.num.ok_write();
    cout << ' ';
    result.den.ok_write();
    cout << endl;
    // cout << "! " << result.num << ' ' << result.den << endl;
    // print("!", result.num, result.den);
    // io.flush();
}

int main() {
    using namespace std;
    cin.tie(nullptr)->sync_with_stdio(false);
    int t;
    cin >> t;
    while (t--) {
        solve();
    }
    // multipleTests([&] {
    //     solve();
    // });
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3632kb

input:

2
4
3 0
1 3
1 1
0 0
3 2
7 4
3
0 0
999 1000
1000 999
1999 1000

output:

? 3 4
? 5 4
! 3 1
? 3996 4
! 1999 2

result:

ok correct! (2 test cases)

Test #2:

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

input:

9
4
1 1
1 3
3 0
0 0
9 4
7 8
4
0 0
1 3
1 1
3 0
3 4
21 8
4
0 0
3 0
1 2
1 1
3 4
7 8
4
0 0
3 0
1 2
1 1
3 2
7 8
4
0 0
3 0
1 1
1 2
3 4
7 4
3
1000 0
0 0
0 1000
1000 1
4
0 0
1000 0
1000 1000
0 1000
1000 1
1000 1
5
0 1
1000 1000
1000 0
0 1000
1 0
999 1
1000 1
1000 1
9
4 1000
3 1
2 1000
3 1000
1 1
2 1
0 0
1 1...

output:

? 3 4
? 5 4
! 5 2
? 3 4
? 5 4
! 7 2
? 3 4
? 5 4
! 3 2
? 3 4
? 5 4
! 2 1
? 3 4
? 5 4
! 5 2
? 0 4
! 500000 1
? 0 4
? 4000 4
! 1000000 1
? 0 4
? 4 4
? 4000 4
! 1999999 2
? 3 4
? 5 4
? 7 4
? 9 4
? 11 4
? 13 4
? 16 4
! 4003 2

result:

ok correct! (9 test cases)

Test #3:

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

input:

78
8
951 614
927 614
957 614
957 604
937 614
942 619
951 610
927 604
10 1
10 1
15 1
25 4
10 1
10 1
7
562 260
602 250
582 255
587 260
602 260
562 250
577 260
10 1
10 1
5 1
10 1
10 1
3
454 98
494 68
455 68
117 4
3
526 589
566 559
527 559
117 4
3
854 496
854 466
894 466
30 1
3
797 264
827 254
857 264
1...

output:

? 3708 4
? 3748 4
? 3768 4
? 3803 4
? 3805 4
? 3828 4
! 317 1
? 2248 4
? 2308 4
? 2328 4
? 2348 4
? 2408 4
! 375 1
? 1820 4
! 585 1
? 2108 4
! 585 1
? 3416 4
! 600 1
? 3308 4
! 300 1
? 2876 4
! 600 1
? 648 4
! 400 1
? 2968 4
? 2987 4
? 2989 4
? 3007 4
? 3009 4
? 3168 4
! 275 1
? 3728 4
? 3747 4
? 37...

result:

ok correct! (78 test cases)

Test #4:

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

input:

34
24
123 815
168 800
133 795
27 827
153 805
28 830
178 780
138 810
78 830
192 772
148 790
88 810
43 825
183 795
103 805
163 785
118 800
93 825
63 835
73 815
58 820
198 790
48 840
108 820
10 3
95 6
15 2
95 6
15 2
95 6
15 2
95 6
15 2
95 6
15 2
95 6
15 2
95 6
15 2
95 6
15 2
95 6
15 2
95 6
15 2
15 1
24...

output:

? 112 4
? 172 4
? 192 4
? 232 4
? 252 4
? 292 4
? 312 4
? 352 4
? 372 4
? 412 4
? 432 4
? 472 4
? 492 4
? 532 4
? 552 4
? 592 4
? 612 4
? 652 4
? 672 4
? 712 4
? 732 4
? 768 4
! 1925 1
? 216 4
? 276 4
? 296 4
? 336 4
? 356 4
? 396 4
? 416 4
? 456 4
? 476 4
? 516 4
? 536 4
? 576 4
? 596 4
? 636 4
? 6...

result:

ok correct! (34 test cases)

Test #5:

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

input:

47
50
227 745
183 763
230 745
208 936
223 745
220 936
232 937
183 759
183 751
226 745
207 762
207 754
207 748
224 745
207 756
207 764
207 758
230 936
232 745
231 936
222 745
221 745
228 745
183 755
224 936
208 747
183 767
183 757
207 750
231 745
183 761
225 936
183 765
229 745
227 936
183 749
207 76...

output:

? 732 4
? 827 4
? 829 4
? 831 4
? 833 4
? 880 4
? 883 4
? 885 4
? 887 4
? 889 4
? 891 4
? 893 4
? 895 4
? 897 4
? 899 4
? 901 4
? 903 4
? 905 4
? 907 4
? 909 4
? 911 4
? 913 4
? 915 4
? 917 4
? 919 4
? 921 4
? 923 4
? 925 4
? 928 4
! 1600 1
? 1199 4
? 1201 4
? 1203 4
? 1205 4
? 1207 4
? 1209 4
? 121...

result:

ok correct! (47 test cases)

Test #6:

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

input:

6
200
359 161
391 193
374 252
387 189
378 252
362 165
395 197
446 252
358 161
377 252
384 252
382 252
352 155
397 199
444 247
412 252
395 252
401 252
391 252
419 252
421 252
401 203
431 233
444 252
434 237
385 252
450 252
421 223
367 252
428 252
379 252
419 221
402 252
430 252
387 252
353 252
396 19...

output:

? 1400 4
? 1407 4
? 1409 4
? 1411 4
? 1413 4
? 1415 4
? 1417 4
? 1419 4
? 1421 4
? 1423 4
? 1425 4
? 1427 4
? 1429 4
? 1431 4
? 1433 4
? 1435 4
? 1437 4
? 1439 4
? 1441 4
? 1443 4
? 1445 4
? 1447 4
? 1449 4
? 1451 4
? 1453 4
? 1455 4
? 1457 4
? 1459 4
? 1461 4
? 1463 4
? 1465 4
? 1467 4
? 1469 4
? 1...

result:

ok correct! (6 test cases)

Test #7:

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

input:

30
57
482 166
584 167
538 167
506 167
618 166
526 168
563 166
629 168
547 168
475 167
583 167
582 167
546 168
471 167
628 168
593 166
634 167
521 166
557 167
539 167
476 167
470 168
505 167
580 168
465 166
514 167
653 167
617 167
570 167
562 166
619 166
472 167
660 166
520 166
491 167
558 167
635 16...

output:

? 1860 4
? 1875 4
? 1877 4
? 1879 4
? 1881 4
? 1884 4
? 1888 4
? 1900 4
? 1904 4
? 1928 4
? 1932 4
? 1960 4
? 1964 4
? 2020 4
? 2024 4
? 2056 4
? 2060 4
? 2080 4
? 2084 4
? 2104 4
? 2108 4
? 2152 4
? 2156 4
? 2184 4
? 2188 4
? 2228 4
? 2232 4
? 2248 4
? 2252 4
? 2280 4
? 2284 4
? 2316 4
? 2320 4
? 2...

result:

ok correct! (30 test cases)

Test #8:

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

input:

12
20
69 340
411 520
513 767
826 881
199 805
622 48
945 965
677 968
388 519
825 72
122 508
448 348
982 932
838 965
448 182
716 450
8 857
346 351
792 433
224 449
117548 223
47161313 84517
7549481525 24425413
73924992225 225575873
42227227870624 157226383481
1076496201908 3834789841
6882360591313 2278...

output:

? 276 4
? 488 4
? 796 4
? 896 4
? 1384 4
? 1552 4
? 1644 4
? 1791 4
? 1793 4
? 2052 4
? 2488 4
? 2708 4
? 2864 4
? 3168 4
? 3300 4
? 3304 4
? 3352 4
? 3780 4
! 566163 2
? 400 4
? 476 4
? 492 4
? 564 4
? 608 4
? 640 4
? 712 4
? 720 4
? 732 4
? 736 4
? 744 4
? 816 4
? 852 4
? 884 4
? 968 4
? 1096 4
? ...

result:

ok correct! (12 test cases)

Test #9:

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

input:

47
100
336 60
627 234
594 968
147 351
511 151
134 433
343 690
97 981
734 678
968 833
962 4
34 977
889 172
227 46
138 713
578 695
193 895
835 513
562 707
504 571
490 366
108 605
440 145
141 743
155 214
143 633
839 995
493 751
480 254
317 587
491 988
537 549
915 465
403 233
343 112
12 236
965 847
710 ...

output:

? 28 4
? 48 4
? 132 4
? 135 4
? 137 4
? 152 4
? 172 4
? 388 4
? 416 4
? 432 4
? 528 4
? 536 4
? 552 4
? 563 4
? 565 4
? 572 4
? 588 4
? 620 4
? 772 4
? 908 4
? 940 4
? 1008 4
? 1012 4
? 1072 4
? 1164 4
? 1180 4
? 1260 4
? 1268 4
? 1328 4
? 1344 4
? 1371 4
? 1373 4
? 1408 4
? 1420 4
? 1440 4
? 1592 4...

result:

ok correct! (47 test cases)

Test #10:

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

input:

5
183
529 552
529 553
526 556
534 552
536 555
528 547
526 553
540 545
535 552
534 555
530 552
535 550
537 550
526 550
534 547
535 556
526 551
530 549
530 551
525 560
525 558
528 551
535 558
537 547
538 560
531 553
533 547
526 558
530 546
531 558
535 554
527 560
534 549
532 557
534 553
540 557
527 54...

output:

? 2096 4
? 2099 4
? 2101 4
? 2103 4
? 2105 4
? 2107 4
? 2109 4
? 2111 4
? 2113 4
? 2115 4
? 2117 4
? 2119 4
? 2121 4
? 2123 4
? 2125 4
? 2127 4
? 2129 4
? 2131 4
? 2133 4
? 2135 4
? 2137 4
? 2139 4
? 2141 4
? 2143 4
? 2145 4
? 2147 4
? 2149 4
? 2151 4
? 2153 4
? 2155 4
? 2157 4
? 2160 4
! 287 2
? 40...

result:

ok correct! (5 test cases)

Test #11:

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

input:

5
195
548 38
540 29
547 28
544 29
542 33
549 37
541 26
546 33
543 38
545 33
545 26
546 24
539 35
542 26
545 35
536 28
541 28
538 33
539 31
540 24
540 25
538 32
535 36
544 34
542 38
542 28
547 32
539 25
550 25
536 30
545 30
543 23
537 34
534 36
541 29
540 37
544 26
535 29
548 36
539 27
546 32
549 29
...

output:

? 2136 4
? 2139 4
? 2141 4
? 2143 4
? 2145 4
? 2147 4
? 2149 4
? 2151 4
? 2153 4
? 2155 4
? 2157 4
? 2159 4
? 2161 4
? 2163 4
? 2165 4
? 2167 4
? 2169 4
? 2171 4
? 2173 4
? 2175 4
? 2177 4
? 2179 4
? 2181 4
? 2183 4
? 2185 4
? 2187 4
? 2189 4
? 2191 4
? 2193 4
? 2195 4
? 2197 4
? 2200 4
! 287 2
? 38...

result:

ok correct! (5 test cases)

Test #12:

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

input:

6
191
562 409
558 414
549 405
549 414
550 403
562 398
553 412
554 410
563 410
548 401
548 413
548 412
552 407
554 408
556 410
552 403
552 412
549 411
563 414
558 404
559 402
550 411
560 403
556 408
562 404
548 414
562 412
559 403
551 400
562 399
547 407
560 406
548 410
562 402
553 414
558 408
553 40...

output:

? 2188 4
? 2191 4
? 2193 4
? 2195 4
? 2197 4
? 2199 4
? 2201 4
? 2203 4
? 2205 4
? 2207 4
? 2209 4
? 2211 4
? 2213 4
? 2215 4
? 2217 4
? 2219 4
? 2221 4
? 2223 4
? 2225 4
? 2227 4
? 2229 4
? 2231 4
? 2233 4
? 2235 4
? 2237 4
? 2239 4
? 2241 4
? 2243 4
? 2245 4
? 2247 4
? 2249 4
? 2252 4
! 287 2
? 38...

result:

ok correct! (6 test cases)

Test #13:

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

input:

100
4
432 383
378 564
879 428
360 237
55425 173
20674 173
9
403 900
991 82
251 377
546 339
621 826
476 904
167 637
184 206
569 464
127483 2814
5064736823 19572978
1686763227553 5774028510
48297246268163 95848873266
57736816891 86762722
82744792 117015
554528 807
7
750 849
303 479
508 268
604 865
208...

output:

? 1512 4
? 1728 4
! 41469 1
? 736 4
? 1004 4
? 1612 4
? 1904 4
? 2184 4
? 2276 4
? 2484 4
! 301579 1
? 1212 4
? 2032 4
? 2416 4
? 3000 4
? 3164 4
! 324517 1
? 912 4
? 1288 4
! 30319 1
? 360 4
? 584 4
? 716 4
? 728 4
? 1184 4
? 1256 4
? 1272 4
? 1304 4
? 1648 4
? 1780 4
? 1784 4
? 1804 4
? 1876 4
? 2...

result:

ok correct! (100 test cases)

Test #14:

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

input:

10
9
243 378
841 782
148 442
136 745
35 882
560 780
385 85
443 884
953 473
28049 204
89873 204
25756 51
81469 102
19903 35
14729 199
87053 393
17
556 767
642 508
179 298
744 572
69 787
592 841
213 929
11 152
949 762
520 41
523 827
371 990
757 661
981 146
419 519
350 27
957 818
340721 4746
3276445 40...

output:

? 544 4
? 592 4
? 972 4
? 1540 4
? 1772 4
? 2240 4
? 3364 4
! 558135 2
? 276 4
? 716 4
? 852 4
? 1400 4
? 1484 4
? 1676 4
? 2080 4
? 2092 4
? 2224 4
? 2368 4
? 2568 4
? 2976 4
? 3028 4
? 3796 4
? 3828 4
! 504173 1
? 4 4
? 24 4
? 44 4
? 88 4
? 140 4
? 164 4
? 224 4
? 288 4
? 324 4
? 368 4
? 384 4
? 4...

result:

ok correct! (10 test cases)

Test #15:

score: 0
Accepted
time: 21ms
memory: 3884kb

input:

1
999
418 860
741 570
398 686
307 967
125 323
595 219
949 428
230 577
401 658
192 266
63 130
526 928
958 736
574 300
248 530
360 734
982 201
542 337
110 305
344 477
855 188
331 887
1000 410
267 449
231 634
726 482
661 708
625 719
345 3
976 556
974 446
989 64
688 137
677 862
563 762
412 960
434 947
3...

output:

? 0 4
? 4 4
? 8 4
? 11 4
? 13 4
? 20 4
? 24 4
? 31 4
? 33 4
? 35 4
? 37 4
? 40 4
? 44 4
? 48 4
? 52 4
? 56 4
? 64 4
? 72 4
? 76 4
? 87 4
? 89 4
? 96 4
? 100 4
? 104 4
? 112 4
? 115 4
? 117 4
? 123 4
? 125 4
? 143 4
? 145 4
? 152 4
? 156 4
? 160 4
? 164 4
? 168 4
? 172 4
? 187 4
? 189 4
? 191 4
? 193...

result:

ok correct! (1 test case)

Test #16:

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

input:

100
8
965 686
363 95
657 171
462 37
13 372
46 611
839 946
375 291
92791 350
515383 793
363975 793
45734 61
42585 61
10355 22
7
384 464
164 845
825 46
292 87
14 238
329 616
458 275
95698 139
95758 165
6914 13
4993 13
2610 13
8
334 854
907 218
140 497
950 599
247 987
849 255
492 689
53 952
119329 281
...

output:

? 184 4
? 1452 4
? 1500 4
? 1848 4
? 2628 4
? 3356 4
! 485819 1
? 656 4
? 1168 4
? 1316 4
? 1536 4
? 1832 4
! 474169 2
? 560 4
? 988 4
? 1336 4
? 1968 4
? 3396 4
? 3628 4
! 364259 1
? 176 4
? 368 4
? 396 4
? 408 4
? 876 4
? 1108 4
? 1736 4
? 1788 4
? 2524 4
? 2920 4
? 2964 4
? 3200 4
? 3212 4
? 3420...

result:

ok correct! (100 test cases)

Test #17:

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

input:

10
127
381 549
297 504
961 486
673 617
737 870
639 562
438 661
210 337
884 488
670 963
887 728
271 264
992 860
260 650
187 121
685 794
448 797
572 932
352 480
927 172
880 121
470 933
485 258
273 288
698 340
539 671
149 299
829 56
371 971
576 105
862 199
926 209
585 837
378 125
492 202
359 453
274 57...

output:

? 112 4
? 164 4
? 168 4
? 216 4
? 240 4
? 268 4
? 340 4
? 364 4
? 376 4
? 380 4
? 532 4
? 552 4
? 588 4
? 596 4
? 608 4
? 640 4
? 680 4
? 740 4
? 748 4
? 840 4
? 852 4
? 888 4
? 976 4
? 988 4
? 1040 4
? 1072 4
? 1084 4
? 1092 4
? 1096 4
? 1100 4
? 1136 4
? 1188 4
? 1252 4
? 1300 4
? 1332 4
? 1336 4
...

result:

ok correct! (10 test cases)

Test #18:

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

input:

1
997
31 967
561 563
77 899
278 232
905 414
944 891
688 470
35 589
72 942
912 459
797 102
496 946
508 427
925 744
217 287
86 2
702 732
965 675
901 433
59 200
732 623
139 180
671 907
195 275
2 631
632 574
318 798
293 785
987 60
638 532
627 641
762 432
792 837
452 842
205 700
50 874
92 920
45 76
701 8...

output:

? 4 4
? 8 4
? 12 4
? 16 4
? 20 4
? 24 4
? 28 4
? 32 4
? 36 4
? 40 4
? 44 4
? 48 4
? 52 4
? 56 4
? 60 4
? 64 4
? 68 4
? 72 4
? 76 4
? 80 4
? 84 4
? 88 4
? 92 4
? 96 4
? 100 4
? 104 4
? 108 4
? 112 4
? 116 4
? 120 4
? 124 4
? 128 4
? 132 4
? 136 4
? 140 4
? 144 4
? 148 4
? 152 4
? 156 4
? 160 4
? 164 ...

result:

ok correct! (1 test case)

Test #19:

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

input:

100
22
440 908
780 215
694 883
610 182
854 925
209 611
697 442
555 903
411 296
641 308
957 488
655 836
474 34
736 125
2 734
740 68
204 1000
536 750
584 558
96 296
518 344
761 693
469436 5037
86355113 277035
107224476167 332586540
876958338859 1648151076
505945614769 921273210
9254733032 17060615
508...

output:

? 384 4
? 816 4
? 836 4
? 1644 4
? 1760 4
? 1896 4
? 2072 4
? 2144 4
? 2220 4
? 2336 4
? 2440 4
? 2564 4
? 2620 4
? 2776 4
? 2788 4
? 2944 4
? 2960 4
? 3044 4
? 3120 4
? 3416 4
! 845077 2
? 1132 4
? 2136 4
? 2412 4
? 2908 4
! 136715 1
? 300 4
? 384 4
? 584 4
? 824 4
? 896 4
? 1000 4
? 1136 4
? 1328 ...

result:

ok correct! (100 test cases)

Test #20:

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

input:

10
215
866 948
174 934
755 317
949 514
727 601
975 939
354 571
564 669
827 916
716 597
924 608
878 628
78 982
402 504
516 660
465 345
357 556
741 143
967 133
414 82
297 81
785 123
48 119
338 647
95 452
958 680
441 817
270 30
587 615
137 446
836 389
358 173
495 398
94 140
922 411
533 933
444 470
352 ...

output:

? 28 4
? 56 4
? 100 4
? 144 4
? 156 4
? 172 4
? 192 4
? 196 4
? 228 4
? 276 4
? 300 4
? 312 4
? 320 4
? 340 4
? 364 4
? 368 4
? 372 4
? 376 4
? 380 4
? 408 4
? 420 4
? 444 4
? 452 4
? 456 4
? 460 4
? 468 4
? 488 4
? 492 4
? 532 4
? 536 4
? 548 4
? 560 4
? 592 4
? 604 4
? 660 4
? 668 4
? 692 4
? 696 ...

result:

ok correct! (10 test cases)

Test #21:

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

input:

1
1000
903 972
368 25
864 957
138 863
388 590
405 404
399 134
629 850
884 984
423 555
213 440
749 211
706 435
140 139
506 853
180 993
280 110
365 362
406 645
490 961
238 159
232 914
267 94
830 951
622 933
631 436
771 112
825 149
38 82
572 322
411 147
329 161
511 500
748 217
906 209
800 887
990 938
2...

output:

? 4 4
? 8 4
? 12 4
? 16 4
? 20 4
? 24 4
? 28 4
? 32 4
? 36 4
? 40 4
? 44 4
? 48 4
? 52 4
? 56 4
? 60 4
? 64 4
? 68 4
? 72 4
? 76 4
? 80 4
? 84 4
? 88 4
? 92 4
? 96 4
? 100 4
? 104 4
? 108 4
? 112 4
? 116 4
? 120 4
? 124 4
? 128 4
? 132 4
? 136 4
? 140 4
? 144 4
? 148 4
? 152 4
? 156 4
? 160 4
? 164 ...

result:

ok correct! (1 test case)

Test #22:

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

input:

100
9
387 4
620 974
157 175
47 935
157 893
978 751
978 543
387 610
620 842
157601 220
82556 115
69704 115
333881609 550812
417151019 550812
176374043 282104
208 1
38
678 102
793 490
747 91
930 210
409 297
585 383
922 937
573 945
770 164
963 160
741 69
63 8
678 201
656 412
51 3
585 10
300 313
619 305...

output:

? 627 4
? 629 4
? 1547 4
? 1549 4
? 2479 4
? 2481 4
? 3912 4
! 999589 2
? 251 4
? 253 4
? 1199 4
? 1201 4
? 1635 4
? 1637 4
? 1791 4
? 1793 4
? 2291 4
? 2293 4
? 2339 4
? 2341 4
? 2476 4
? 2531 4
? 2533 4
? 2624 4
? 2711 4
? 2713 4
? 2963 4
? 2965 4
? 2987 4
? 2989 4
? 3079 4
? 3081 4
? 3172 4
? 322...

result:

ok correct! (100 test cases)

Test #23:

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

input:

10
265
711 246
635 106
363 296
298 516
148 548
20 264
717 993
976 382
212 151
338 427
107 918
15 648
573 138
733 967
828 489
444 793
758 988
740 898
227 906
592 734
625 702
728 912
824 323
821 483
403 571
188 872
817 384
637 685
76 375
500 685
725 299
960 630
805 902
450 638
289 548
510 181
788 975
...

output:

? 20 4
? 59 4
? 61 4
? 79 4
? 81 4
? 131 4
? 133 4
? 179 4
? 181 4
? 183 4
? 185 4
? 259 4
? 261 4
? 287 4
? 289 4
? 303 4
? 305 4
? 343 4
? 345 4
? 407 4
? 409 4
? 427 4
? 429 4
? 479 4
? 481 4
? 495 4
? 497 4
? 515 4
? 517 4
? 591 4
? 593 4
? 651 4
? 653 4
? 663 4
? 665 4
? 715 4
? 717 4
? 751 4
?...

result:

ok correct! (10 test cases)

Test #24:

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

input:

1
1000
223 436
120 685
243 500
776 484
710 948
428 611
155 840
733 209
193 469
730 884
889 899
271 55
5 495
435 573
757 224
477 493
240 827
515 664
764 929
495 443
397 912
685 352
236 819
691 276
538 348
101 934
592 69
741 90
720 693
85 849
130 885
271 752
531 849
247 41
513 181
298 458
189 475
712 ...

output:

? 8 4
? 19 4
? 21 4
? 27 4
? 29 4
? 35 4
? 37 4
? 43 4
? 45 4
? 47 4
? 49 4
? 51 4
? 53 4
? 83 4
? 85 4
? 107 4
? 109 4
? 115 4
? 117 4
? 135 4
? 137 4
? 159 4
? 161 4
? 219 4
? 221 4
? 223 4
? 225 4
? 231 4
? 233 4
? 259 4
? 261 4
? 275 4
? 277 4
? 283 4
? 285 4
? 295 4
? 297 4
? 303 4
? 305 4
? 31...

result:

ok correct! (1 test case)

Test #25:

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

input:

100
4
1 1000
0 0
517 791
377 129
376871 377
92713 129
9
168 332
1 0
262 723
263 932
291 27
258 311
71 543
0 1000
70 339
262932 263
74399631 76270
82331595 106778
9302862573 14567570
7300316613 14567570
40056563 86790
1165514 4785
7
494 277
1 1000
0 0
696 595
277 739
435 88
54 196
434912 435
12525677...

output:

? 4 4
? 1508 4
! 747723 2
? 4 4
? 280 4
? 284 4
? 672 4
? 1032 4
? 1048 4
? 1052 4
! 389725 2
? 4 4
? 216 4
? 1108 4
? 1740 4
? 1976 4
! 362785 1
? 3940 4
? 3996 4
! 116785 1
? 468 4
? 604 4
? 1056 4
? 1136 4
? 1168 4
? 1412 4
? 1856 4
? 1928 4
? 1964 4
? 1988 4
? 2440 4
? 2552 4
? 2660 4
? 3124 4
?...

result:

ok correct! (100 test cases)

Test #26:

score: -100
Runtime Error

input:

10
9
496 52
825 592
0 0
1 1000
853 985
7 125
526 89
736 767
943 521
123987 124
8796609 8804
446131323 638716
2385697 3692
2044027 3692
1441987 8307
70740 767
17
407 499
296 912
463 41
575 862
293 242
219 602
717 283
29 11
371 775
999 1000
875 460
440 332
247 733
130 817
667 304
1000 0
56 683
457704 ...

output:

? 4 4
? 28 4
? 1984 4
? 2104 4
? 2944 4
? 3300 4
? 3412 4
! 1215909 2
? 224 4
? 520 4
? 876 4
? 988 4
? 1172 4
? 1184 4
? 1484 4
? 1628 4
? 1760 4
? 1852 4
? 2300 4
? 2668 4
? 2868 4
? 3500 4
? 3996 4
! 1163041 2
? 4 4
? 12 4
? 48 4
? 56 4
? 68 4
? 124 4
? 144 4
? 148 4
? 200 4
? 204 4
? 212 4
? 224...

result: