#include #include #include #include using namespace std; #define RREP(i,s,e) for (i = s; i >= e; i--) #define rrep(i,n) RREP(i,n,0) #define REP(i,s,e) for (i = s; i < e; i++) #define rep(i,n) REP(i,0,n) #define INF 100000000 typedef long long ll; int main() { int i, j, k, l, n, x, y, dir; int dxy[4] = {1,0,-1,0}; int s[39][39] {}; int d[39][39]; x = y = 19; dir = 0; s[x][y] = 1; cin >> n; for (;;) { for (i = 0; i < 4 && n != 20151224; i++) { s[x+(n+1)*dxy[dir]][y+(n+1)*dxy[(dir+1)%4]] = 2; while (n--) s[x+(n+1)*dxy[dir]][y+(n+1)*dxy[(dir+1)%4]] = 1; cout << "L" << endl; cin >> n; dir = (dir + 1) % 4; } if (n == 20151224) break; bool found = false; REP (i,1,37) REP (j,1,37) if (!found && !s[i][j]) { rep (k,4) if (s[i+dxy[k]][j+dxy[(k+1)%4]] == 1) { queue> q; q.push(make_pair(i+dxy[k],j+dxy[(k+1)%4])); rep (l,39) fill(d[l],d[l]+39,INF); d[i+dxy[k]][j+dxy[(k+1)%4]] = 0; while (!q.empty()) { int a, b; tie(a,b) = q.front(); q.pop(); if (a == x && b == y) break; rep (l,4) { int na, nb; na = a+dxy[l]; nb = b+dxy[(l+1)%4]; if (s[na][nb] == 1 && d[a][b] + 1 < d[na][nb]) { d[na][nb] = d[a][b] + 1; q.push(make_pair(na,nb)); } } } while (d[x][y] > 0) { while (d[x][y] != d[x+dxy[dir]][y+dxy[(dir+1)%4]] + 1) { cout << "L" << endl; cin >> n; dir = (dir + 1) % 4; } cout << "F" << endl; cin >> n; x += dxy[dir]; y+= dxy[(dir+1)%4]; } found = true; } } } cin.ignore(); string str; while (cout << "F" << endl, getline(cin,str), str != "Merry Christmas!"); return 0; }