#include using ll = long long; using namespace std; array b[25][1100]; array b1[25][1100]; int main() { int x = 12, y = 0, l = 100; for (int turn = 0; turn < 1000; turn++) { int n; cin >> n; if (n < 0) exit(0); for (int i = 0; i < n; i++) { int h, p, x; cin >> h >> p >> x; b[x][y + 60] = { h, p, h }; } y++; int m = l / 100; char c = 'S'; int r[25], o[25] = {}; for (int i = 0; i < 25; i++) { int s = 100000; int d = abs(x - i); d = min(d, 25 - d); d = max(d - 1, 0); if (auto h = b[i][y + 1 + d][0]; h > m) o[i] = 1; for (int j = 1 + d; j < 60; j++) { if (auto h = b[i][y + j][0]; h > 0) { int t = (h + m - 1) / m + d; int p = b[i][y + j][1]; if (t > j) s = 200000; else s = -1000000 * pow(p, m > 200 ? 0 : 1) / t; break; } } for (int j = 1 + d; j < 60; j++) { if (auto h = b[i][y + j][0]; h > 0) { s--; } } r[i] = s; } int t[2] = {}; for (int i = 1; i <= 12; i++) { if (int x0 = (x + i + 25) % 25; t[0] |= b[x0][y - 1 + i][0] | o[x0]) r[x0] = 300000; if (int x1 = (x - i + 25) % 25; t[1] |= b[x1][y + 1 - i][0] | o[x1]) r[x1] = 300000; } if (int i = min_element(r, r + 25) - r; i != x) c = "LR"[i - x > 0 ^ abs(i - x) > 12]; if (m > 200) { int L = min(5, 1000 - turn); int s0 = 0; for (int k = 0; k < (int)pow(3, L); k++) { int p[10] = {}, t = k; for (int i = 0; i < L; i++) { p[i] = t % 3 - 1; t /= 3; } int s = 0; int x1 = x, y1 = y, l1 = l; for (int i = 0; i < 25; i++) { for (int j = y; j < y + 60; j++) { b1[i][j] = b[i][j]; } } for (int i = 0; i < L; i++) { x1 += p[i]; if (x1 < 0) x1 += 25; if (x1 >= 25) x1 -= 25; if (b1[x1][y1][0]) { s = 0; break; } for (int j = 1; j < 60; j++) { if (auto &h = b1[x1][y1 + j][0]; h > 0) { h -= l1 / 100; if (h <= 0) { h = 0; l1 += b1[x1][y1 + j][1]; s += b1[x1][y1 + j][2]; } break; } } y1++; if (b1[x1][y1][0]) { s = 0; break; } } if (s > s0) { s0 = s; if (r[(x + p[0] + 25) % 25] < 0) c = "LSR"[p[0] + 1]; } } } cout << "#" << x << ' ' << y << ' ' << min_element(r, r + 25) - r << '\n'; cout << '#'; for (int i = 0; i < 25; i++) { cout << r[i] << " \n"[i == 24]; } cout << c << endl; x += (c == 'R') - (c == 'L'); x = (x + 25) % 25; for (int j = 1; j < 60; j++) { if (auto &h = b[x][y + j][0]; h > 0) { h -= m; if (h <= 0) { h = 0; l += b[x][y + j][1]; } cout << "#" << l << ' ' << h << '\n'; break; } } } return 0; }