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
#include <bits/stdc++.h>
#include <iostream>
#define nl '\n'

using namespace std;
using pii = pair<int, int>;
const int MAXN = 2e3+1;

vector<pii> G[MAXN];
vector<int> dist(MAXN, 1<<30);

void send(int val, int bits){
	while(bits--){
		cout<<"+ "<<(val & 1)<<endl;
		cout.flush();
		val >>= 1;
	}
}

int read(int bits){
	int res = 0;
	for(int i=0; i<bits; i++){
		cout<<"?"<<endl;
		cout.flush();
		int b;
		cin>>b;
		res |= b<<i;
	}
	return res;
}

string role;

int n;

void dijkstra(){
	//dist[1] = 0;
	priority_queue<pii> q;
	q.push({0, 1});
	int last_dist = 0;
	int set_cnt = 0;
	while(set_cnt < n) {
		auto [d, v] = q.empty() ? (pii){-last_dist-511, 0} : q.top();
		d = -d;
		if(role == "Algosia"){
		//	cerr<<role<<' '<<d<<' '<<v<<nl;
		}
		if(dist[v] < 1<<30){ q.pop(); continue; }
		//if(v != 0){
			send(d-last_dist, 9);
		//}else{
		//	send(511, 9);
		//}
		int d2 = last_dist + read(9);
		if(d < d2 || (d == d2 && role == "Algosia")){
			send(v, 11);
			q.pop();
		}else{
			d = d2;
			v = read(11);
		}
		if(role == "Algosia"){
		//	cerr<<v<<' '<<d<<' '<<d2<<nl;
		}
		last_dist = d;
		dist[v] = d;
		set_cnt++;
		for(auto [i, c]: G[v]){
			if(dist[i] > d + c){
				//dist[i] = d + c;
				q.push({-d - c, i});
			}
		}
	}
}

int main()
{
	cin.tie(0)->sync_with_stdio(0);
	cin>>role;
	int m;
	cin>>n>>m;
	while(m--){
		int a, b, c;
		cin>>a>>b>>c;
		G[a].push_back({b, c});
		G[b].push_back({a, c});
	}
	dijkstra();
	if(role == "Algosia"){
		cout<<"! ";
		for(int i=1; i<=n; i++){
			cout<<dist[i]<<' ';
		//	cerr<<dist[i]<<' ';
		}
		cout<<nl;
		//cerr<<nl;
	}
	return 0;
}