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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#include<bits/stdc++.h>
using namespace std;

#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define ST first
#define ND second
#define PB push_back
using ll = long long;
using ld = long double;
using pi = pair<int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;


#ifdef LOCAL
#define DTP(x, y)                                    \
    auto operator<<(auto &o, auto a)->decltype(y, o) \
    {                                                \
        o << "(";                                    \
        x;                                           \
        return o << ")";                             \
    }
DTP(o << a.first << ", " << a.second, a.second);
DTP(for (auto i : a) o << i << ", ", all(a));
void dump(auto... x) { ((cerr << x << ", "), ...) << '\n'; }
#define debug(x...) cerr << setw(4) << __LINE__ << ":[" #x "]: ", dump(x)
#else
#define debug(...) 0
#endif

void Write(int x, int k){
    rep(i, 0, k){
        cout << "+ " << x%2 << endl;
        x/=2;
    }
    return;
}

int Read(int k){
    int pow=1;
    int res=0;
    int a;
    rep(i, 0, k){
        cout << "? " << endl;
        cin >> a;
        res+=a*pow;
        pow*=2;
    }
    return res;
}

void SolveA()
{
    int n, m;
    cin >> n >> m;
    vector<vector<pi>> E(n);
    rep(i, 0, m){
        int a, b, c;
        cin >> a >> b >> c;
        E[--a].PB(pi(--b, c));
        E[b].PB(pi(a, c));
    }
    vi V(n, -1);
    V[0]=0;
    int curr=0;
    int left=n-1;
    priority_queue<pi> Q;
    for(auto &[x,y]: E[0])
        Q.push(pi(-y, x));
    while(left--){
        while(!Q.empty() && V[Q.top().ND]!=-1)
            Q.pop();
        pi t={511, 0};
        if(!Q.empty()){
            t=Q.top();
            t.ST=-t.ST-curr;
        }
        Write(t.ST, 9);
        int t2=Read(9);
        if(t.ST<=t2){
            Write(t.ND, 11);
            V[t.ND]=t.ST+curr;
            curr=V[t.ND];
            for(auto &[x,y]: E[t.ND])
                Q.push(pi(-V[t.ND]-y, x));
        }else{
            int v=Read(11);
            V[v]=curr+t2;
            curr=V[v];
            for(auto &[x,y]: E[v])
                Q.push(pi(-V[v]-y, x));
        }
    }
    cout << "! ";
    rep(i, 0, n)
        cout << V[i] << ' ';
    return;
}

void SolveB()
{
    int n, m;
    cin >> n >> m;
    vector<vector<pi>> E(n);
    rep(i, 0, m){
        int a, b, c;
        cin >> a >> b >> c;
        E[--a].PB(pi(--b, c));
        E[b].PB(pi(a, c));
    }
    vi V(n, -1);
    V[0]=0;
    int curr=0;
    int left=n-1;
    priority_queue<pi> Q;
    for(auto &[x,y]: E[0])
        Q.push(pi(-y, x));
    while(left--){
        while(!Q.empty() && V[Q.top().ND]!=-1)
            Q.pop();
        pi t2={511, 0};
        if(!Q.empty()){
            t2=Q.top();
            t2.ST=-t2.ST-curr;
        }
        int t=Read(9);
        Write(t2.ST, 9);
        if(t<=t2.ST){
            int v=Read(11);
            V[v]=t+curr;
            curr=V[v];
            for(auto &[x,y]: E[v])
                Q.push(pi(-V[v]-y, x));
        }else{
            Write(t2.ND, 11);
            V[t2.ND]=curr+t2.ST;
            curr=V[t2.ND];
            for(auto &[x,y]: E[t2.ND])
                Q.push(pi(-V[t2.ND]-y, x));
        }
    }
    return;
}


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int t=1;
    // cin >> t;
    string s;
    cin >> s;
    while(t--)
    {
        if(s[0]=='A')
            SolveA();
        else
            SolveB();
    }
    return 0;
}