1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#include <algorithm>
#include <iostream>
#include <queue>

using namespace std;

typedef pair<int, int> pii;
priority_queue<pii, vector<pii>, greater<> > pq;
int msf = 0;
int A[2002];
int G[2002][2002];
vector<vector<int> > E(2002);
int N;

void send(const int val, const int len) {
    for (int i = 0; i < len; ++i) {
        const int b = 1 << i & val ? 1 : 0;
        cout << "+ " << b << "\n";
        cout.flush();
    }
}

int receive(const int len) {
    int res = 0;
    int a;
    for (int i = 0; i < len; ++i) {
        cout << "?" << "\n";
        cout.flush();
        cin >> a;
        res |= a << i;
    }
    return res;
}

void update(int city) {
    for (int j = 0; j < E[city].size(); j++) {
        if (A[E[city][j]] == 0)
            pq.emplace(msf + G[city][E[city][j]], E[city][j]);
    }
}

void AA() {
    A[1] = 0;
    for (int i = 2; i <= N; ++i) {
        while (!pq.empty() && A[pq.top().second] != 0) { pq.pop(); }
        int ts = pq.empty() ? 502 : pq.top().first - msf;
        send(ts, 9);
        int rec = receive(9);
        int city, len;
        if (ts > rec) {
            len = rec;
            city = receive(11);
        } else {
            len = ts;
            city = pq.top().second;
            send(city, 11);
            pq.pop();
        }
        msf += len;
        A[city] = msf;
        update(city);
    }
    cout << "! ";
    for (int i = 1; i <= N; ++i) { cout << A[i] << " "; }
    cout << "\n";
    cout.flush();
}

void BB() {
    A[1] = 0;
    for (int i = 2; i <= N; ++i) {
        while (!pq.empty() && A[pq.top().second] != 0) { pq.pop(); }
        int ts = pq.empty() ? 502 : pq.top().first - msf;
        int rec = receive(9);
        send(ts, 9);
        int city, len;
        if (rec <= ts) {
            len = rec;
            city = receive(11);
        } else {
            len = ts;
            city = pq.top().second;
            send(city, 11);
            pq.pop();
        }
        msf += len;
        A[city] = msf;
        update(city);
    }
}

string name;
int AB;
int U, V, C;

int main() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);

    // int t199 = receive(8);
    // cout << t199;
    // cout.flush();
    // send(199, 8);


    cin >> name;
    cin >> N;
    cin >> AB;
    for (int i = 0; i < AB; ++i) {
        cin >> U >> V >> C;
        if (min(U, V) > 1) {
            E[U].push_back(V);
            E[V].push_back(U);
            G[U][V] = G[V][U] = C;
        } else {
            pq.emplace(C, max(U, V));
        }
    }
    if (name[0] == 'A') AA();
    else BB();

    return 0;
}