#include "message.h"
#include "rps.h"
#include <bits/stdc++.h>
typedef long long int lli;
using namespace std;
const int nnodes = NumberOfNodes();
const int nodeId = MyNodeId();
const int N = (int)GetN();
int main() {
if(!nodeId){
for(int i=1;i<nnodes;i++){
while(1){
Receive(i);
int num = GetInt(i);
if(num==-1){
break;
}
}
}
vector<char> C(1<<N);
vector<int> A(1<<N);
for(int i=0;i<C.size();i++){
A[i] = i;
C[i] = GetFavoriteMove(i);
}
while((int)A.size() != 1){
vector<char> tmp((A.size())>>1);
for(int i=0;i<A.size(); i+=2){ // S P R
if(C[A[i]] == 'S' && C[A[i+1]] == 'P'){
tmp[(i>>1)] = A[i];
}
if(C[A[i]] == 'P' && C[A[i+1]] == 'S'){
tmp[(i>>1)] = A[i+1];
}
if(C[A[i]] == 'P' && C[A[i+1]] == 'R'){
tmp[(i>>1)] = A[i];
}
if(C[A[i]] == 'R' && C[A[i+1]] == 'P'){
tmp[(i>>1)] = A[i+1];
}
if(C[A[i]] == 'S' && C[A[i+1]] == 'R'){
tmp[(i>>1)] = A[i+1];
}
if(C[A[i]] == 'R' && C[A[i+1]] == 'S'){
tmp[(i>>1)] = A[i];
}
if(C[A[i]] == C[A[i+1]]){
tmp[(i>>1)] = A[i];
}
}
A.resize(tmp.size());
for(int i=0;i<tmp.size();i++)
A[i] = tmp[i];
tmp.clear();
}
cout << A[0] << "\n";
}
else{
PutInt(0,-1);
Send(0);
}
return 0;
}
I2luY2x1ZGUgIm1lc3NhZ2UuaCIKI2luY2x1ZGUgInJwcy5oIgojaW5jbHVkZSA8Yml0cy9zdGRjKysuaD4KCnR5cGVkZWYgbG9uZyBsb25nIGludCBsbGk7CnVzaW5nIG5hbWVzcGFjZSBzdGQ7Cgpjb25zdCBpbnQgbm5vZGVzID0gTnVtYmVyT2ZOb2RlcygpOwpjb25zdCBpbnQgbm9kZUlkID0gTXlOb2RlSWQoKTsKY29uc3QgaW50IE4gPSAoaW50KUdldE4oKTsKCmludCBtYWluKCkgewoKCWlmKCF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