Problem: cf1336_d
Difficulty: hard
Categories: math
Time limit: 1000 ms, memory limit: 256 MB

This is an interactive problem.

Yui is a girl who enjoys playing Mahjong.

![](https://espresso.codeforces.com/9f136a513310216e55c661c389978beeca460fe8.png)

She has a mysterious set which consists of tiles (this set can be empty). Each tile has an integer value between $1$ and $n$, and at most $n$ tiles in the set have the same value. So the set can contain at most $n^2$ tiles.

You want to figure out which values are on the tiles. But Yui is shy, she prefers to play a guessing game with you.

Let's call a set consisting of three tiles triplet if their values are the same. For example, $\{2,\,2,\,2\}$ is a triplet, but $\{2,\,3,\,3\}$ is not.

Let's call a set consisting of three tiles straight if their values are consecutive integers. For example, $\{2,\,3,\,4\}$ is a straight, but $\{1,\,3,\,5\}$ is not.

At first, Yui gives you the number of triplet subsets and straight subsets of the initial set respectively. After that, you can insert a tile with an integer value between $1$ and $n$ into the set at most $n$ times. Every time you insert a tile, you will get the number of triplet subsets and straight subsets of the current set as well.

Note that two tiles with the same value are treated different. In other words, in the set $\{1,\,1,\,2,\,2,\,3\}$ you can find $4$ subsets $\{1,\,2,\,3\}$.

Try to guess the number of tiles in the initial set with value $i$ for all integers $i$ from $1$ to $n$.

Input

The first line contains a single integer $n$ ($4 \le n \le 100$).

The second line contains two integers which represent the number of triplet subsets and straight subsets of the initial set respectively.

Output

When you are ready to answer, print a single line of form "! $a_1$ $a_2$ $\ldots$ $a_n$" ($0 \le a_i \le n$), where $a_i$ is equal to the number of tiles in the initial set with value $i$.

Interaction

To insert a tile, print a single line of form "+ $x$" ($1 \le x \le n$), where $x$ is the value of the tile you insert. Then you should read two integers which represent the number of triplet subsets and straight subsets of the current set respectively.

After printing a line, do not forget to flush the output. Otherwise, you will get Idleness limit exceeded. To do this, use:

* fflush(stdout) or cout.flush() in C++;
* System.out.flush() in Java;
* flush(output) in Pascal;
* stdout.flush() in Python;
* see documentation for other languages.

You will get Wrong answer if you insert more than $n$ tiles.

Example

Input

```
5
1 6
2 9
5 12
5 24
6 24
```

Output

```
+ 1
+ 1
+ 2
+ 5
! 2 1 3 0 2
```

Note

In the first test, the initial set of tiles is $\{1, 1, 2, 3, 3, 3, 5, 5\}$. It has only one triplet subset $\{3, 3, 3\}$ and six straight subsets, all equal to $\{1, 2, 3\}$. After inserting a tile with value $1$ the set of tiles will be $\{1, 1, 1, 2, 3, 3, 3, 5, 5\}$ and will have two triplet subsets $\{1, 1, 1\}$, $\{3, 3, 3\}$ and nine straight subsets, all equal to $\{1, 2, 3\}$.

Non-adaptive interactor (C++):
#include "testlib.h"
#include <bits/stdc++.h>
using namespace std;

static long long queries = 0;
static long long query_limit = 0;

static void log_metrics() {
    try {
        tout << "queries=" << queries << endl;
        tout << "query_limit=" << query_limit << endl;
    } catch (...) {
        
    }
}

static void finish(TResult verdict, const string& msg) {
    log_metrics();
    quitf(verdict, "%s", msg.c_str());
}

static bool parseLL(const string& s, long long& out) {
    if (s.empty()) return false;
    int i = 0;
    if (s[0] == '-') {
        i = 1;
        if (i == (int)s.size()) return false;
    } else if (s[0] == '+') {
        return false;
    }
    for (; i < (int)s.size(); i++) {
        if (!isdigit((unsigned char)s[i])) return false;
    }
    try {
        out = stoll(s);
    } catch (...) {
        return false;
    }
    return true;
}

static long long comb3(long long c) {
    if (c < 3) return 0;
    return c * (c - 1) * (c - 2) / 6;
}

static pair<long long, long long> computeCounts(const vector<long long>& c) {
    int n = (int)c.size() - 1;
    long long triplets = 0;
    long long straights = 0;
    for (int i = 1; i <= n; i++) triplets += comb3(c[i]);
    for (int i = 1; i + 2 <= n; i++) straights += c[i] * c[i + 1] * c[i + 2];
    return {triplets, straights};
}

static bool readToken(string& tok) {
    tok.clear();
    if (!(cin >> tok)) return false;
    return true;
}

int main(int argc, char** argv) {
    registerInteraction(argc, argv);
    atexit(log_metrics);

    int n = inf.readInt(4, 100, "n");
    vector<long long> initial(n + 1, 0), cur(n + 1, 0);
    for (int i = 1; i <= n; i++) {
        int ai = inf.readInt(0, n, ("a" + to_string(i)).c_str());
        initial[i] = ai;
        cur[i] = ai;
    }

    query_limit = n;
    log_metrics(); 

    auto [t0, s0] = computeCounts(cur);

    cout << n << "\n";
    cout << t0 << " " << s0 << "\n";
    cout.flush();

    long long hard_cap = max(200000LL, 10LL * query_limit);

    while (true) {
        string cmd;
        if (!readToken(cmd)) finish(_pe, "Unexpected EOF from contestant");

        if (cmd == "+") {
            string xs;
            if (!readToken(xs)) finish(_pe, "Missing x after '+'");
            long long xll;
            if (!parseLL(xs, xll)) finish(_pe, "Non-integer x after '+'");
            if (xll < 1 || xll > n) finish(_pe, "x out of range");
            queries++;
            if (queries > hard_cap) finish(_pe, "Hard cap exceeded");

            int x = (int)xll;
            cur[x]++;

            auto [t, s] = computeCounts(cur);
            cout << t << " " << s << "\n";
            cout.flush();
        } else if (cmd == "!") {
            vector<long long> ans(n + 1, 0);
            for (int i = 1; i <= n; i++) {
                string ts;
                if (!readToken(ts)) finish(_pe, "Missing ai in final answer");
                long long v;
                if (!parseLL(ts, v)) finish(_pe, "Non-integer ai in final answer");
                if (v < 0 || v > n) finish(_pe, "ai out of range in final answer");
                ans[i] = v;
            }
            for (int i = 1; i <= n; i++) {
                if (ans[i] != initial[i]) {
                    finish(_wa, "Wrong final answer");
                }
            }
            finish(_ok, "OK");
        } else {
            finish(_pe, "Invalid command token");
        }
    }
}


Adaptive interactor (C++):
#include "testlib.h"
#include <bits/stdc++.h>
using namespace std;

static long long queries = 0;
static long long query_limit = 0;

static void log_metrics() {
    try {
        tout << "queries=" << queries << '\n';
        tout << "query_limit=" << query_limit << '\n';
        tout.flush();
    } catch (...) {
        
    }
}

static void finish(TResult verdict, const string& msg) {
    log_metrics();
    quitf(verdict, "%s", msg.c_str());
}

static inline string trim_copy(const string& s) {
    size_t l = 0, r = s.size();
    while (l < r && isspace((unsigned char)s[l])) l++;
    while (r > l && isspace((unsigned char)s[r - 1])) r--;
    return s.substr(l, r - l);
}

static long long c3(long long x) {
    if (x < 3) return 0;
    return x * (x - 1) * (x - 2) / 6;
}

static pair<long long, long long> computeTS(const vector<long long>& cnt, int n) {
    long long T = 0, S = 0;
    for (int i = 1; i <= n; i++) T += c3(cnt[i]);
    for (int i = 1; i + 2 <= n; i++) S += cnt[i] * cnt[i + 1] * cnt[i + 2];
    return {T, S};
}

static vector<int> build_deterministic_counts(int n) {
    vector<int> a(n + 1, 0);
    for (int i = 1; i <= n; i++) {
        long long v = (1LL * i * i * 37 + 17LL * i + 23) % (n + 1);
        if (i % 10 == 0) v = n;
        if (i % 7 == 0) v = max<long long>(v, n / 2);
        a[i] = (int)v;
    }
    return a;
}

static bool parse_single_ll(const string& token, long long& out) {
    if (token.empty()) return false;
    size_t i = 0;
    bool neg = false;
    if (token[i] == '+' || token[i] == '-') {
        neg = (token[i] == '-');
        i++;
    }
    if (i >= token.size()) return false;
    long long val = 0;
    for (; i < token.size(); i++) {
        if (!isdigit((unsigned char)token[i])) return false;
        int d = token[i] - '0';
        if (val > (LLONG_MAX - d) / 10) return false;
        val = val * 10 + d;
    }
    out = neg ? -val : val;
    return true;
}

int main(int argc, char** argv) {
    registerInteraction(argc, argv);
    atexit(log_metrics);

    int n = inf.readInt(4, 100);

    vector<int> initial(n + 1, 0);
    bool hasCounts = !inf.seekEof();
    if (hasCounts) {
        for (int i = 1; i <= n; i++) initial[i] = inf.readInt(0, n);
    } else {
        initial = build_deterministic_counts(n);
    }

    vector<long long> cur(n + 1, 0);
    for (int i = 1; i <= n; i++) cur[i] = initial[i];

    query_limit = n;

    
    log_metrics();

    
    auto ts0 = computeTS(cur, n);
    cout << n << "\n";
    cout << ts0.first << " " << ts0.second << "\n";
    cout.flush();

    const long long hard_cap = max(200000LL, 10LL * query_limit);

    while (true) {
        string line;
        if (!std::getline(cin, line)) {
            finish(_pe, "EOF from contestant");
        }
        line = trim_copy(line);
        if (line.empty()) continue;

        char c = line[0];
        if (c == '+') {
            queries++;
            if (queries > hard_cap) finish(_pe, "too many queries (hard cap exceeded)");

            string rest = trim_copy(line.substr(1));
            if (rest.empty()) finish(_pe, "missing x after '+'");

            stringstream ss(rest);
            string tok;
            ss >> tok;
            if (tok.empty()) finish(_pe, "missing x after '+'");
            string extra;
            ss >> extra;
            if (!extra.empty()) finish(_pe, "extra tokens after '+ x'");

            long long xll = 0;
            if (!parse_single_ll(tok, xll)) finish(_pe, "bad integer x after '+'");
            if (xll < 1 || xll > n) finish(_pe, "x out of range after '+'");

            int x = (int)xll;
            cur[x]++;

            auto ts = computeTS(cur, n);
            cout << ts.first << " " << ts.second << "\n";
            cout.flush();
            continue;
        }

        if (c == '!') {
            string rest = trim_copy(line.substr(1));
            vector<long long> ans(n + 1, 0);

            stringstream ss(rest);
            for (int i = 1; i <= n; i++) {
                string tok;
                if (!(ss >> tok)) finish(_pe, "not enough numbers after '!'");
                long long v = 0;
                if (!parse_single_ll(tok, v)) finish(_pe, "bad integer in answer");
                if (v < 0 || v > n) finish(_pe, "answer value out of range");
                ans[i] = v;
            }
            string extra;
            if (ss >> extra) finish(_pe, "too many tokens after answer");

            for (int i = 1; i <= n; i++) {
                if (ans[i] != initial[i]) finish(_wa, "wrong initial multiplicities");
            }
            finish(_ok, "correct");
        }

        finish(_pe, "unknown command");
    }
}


Test generator (C++):
#include "testlib.h"
#include <bits/stdc++.h>
using namespace std;

static vector<int> makeCounts(int n, long long seed) {
    vector<int> a(n + 1, 0);

    if (seed == 1) {
        
        return a;
    }
    if (seed == 2) {
        
        for (int i = 1; i <= n; i++) a[i] = n;
        return a;
    }
    if (seed == 3) {
        
        for (int i = 1; i <= n; i++) {
            int r = i % 3;
            if (r == 1) a[i] = 1;
            else if (r == 2) a[i] = 0;
            else a[i] = min(2, n);
        }
        if (n >= 3) {
            a[1] = n;
            a[2] = n;
            a[3] = n;
        }
        int mid = (n + 1) / 2;
        for (int d = -2; d <= 2; d++) {
            int idx = mid + d;
            if (1 <= idx && idx <= n) a[idx] = n;
        }
        int tail = n - 2;
        if (tail >= 1) a[tail] = n;
        if (tail + 1 >= 1 && tail + 1 <= n) a[tail + 1] = n;
        if (tail + 2 >= 1 && tail + 2 <= n) a[tail + 2] = n;
        return a;
    }

    
    
    for (int i = 1; i <= n; i++) {
        int coin = rnd.next(0, 99);
        if (coin < 55) {
            a[i] = rnd.next(0, 1); 
        } else if (coin < 70) {
            a[i] = rnd.next(0, min(n, 3));
        } else if (coin < 85) {
            int lo = n / 3, hi = (2 * n) / 3;
            if (lo > hi) lo = 0, hi = n;
            a[i] = rnd.next(lo, hi);
        } else {
            a[i] = n;
        }
    }

    
    int minL = max(3, n / 2);
    int L = rnd.next(minL, n);
    int start = rnd.next(1, n - L + 1);
    for (int i = start; i < start + L; i++) {
        int v = rnd.next(max(0, n - 8), n);
        a[i] = v;
    }

    
    int blocks = rnd.next(3, 8);
    for (int b = 0; b < blocks; b++) {
        int len = rnd.next(1, min(7, n));
        int st = rnd.next(1, n - len + 1);
        int base = rnd.next(max(0, n - 12), n);
        for (int i = st; i < st + len; i++) {
            int v = base + rnd.next(-2, 2);
            v = max(0, min(n, v));
            a[i] = max(a[i], v);
        }
    }

    
    if (n >= 4) {
        a[1] = max(a[1], rnd.next(0, n));
        a[2] = max(a[2], rnd.next(0, n));
        a[n - 1] = max(a[n - 1], rnd.next(0, n));
        a[n] = max(a[n], rnd.next(0, n));
    }

    
    for (int i = 1; i <= n; i++) a[i] = max(0, min(n, a[i]));
    return a;
}

int main(int argc, char* argv[]) {
    registerGen(argc, argv, 1);

    string mode = opt<string>("mode", "non");
    int n = opt<int>("n", 100);
    n = max(4, min(100, n));

    long long seed = 0;
    if (argc >= 2) {
        try {
            seed = stoll(string(argv[1]));
        } catch (...) {
            seed = 0;
        }
    }

    if (mode == "adp") {
        
        cout << n << "\n";
        return 0;
    }

    
    vector<int> a = makeCounts(n, seed);

    cout << n << "\n";
    for (int i = 1; i <= n; i++) {
        if (i > 1) cout << ' ';
        cout << a[i];
    }
    cout << "\n";
    return 0;
}