#include using namespace std; using u32 = uint32_t; using u64 = uint64_t; u32 nextState(u32 x) { x ^= x << 13; x ^= x >> 17; x ^= x << 5; return x; } array nextSymbolic(array x) { array y = x; for (int i = 13; i < 32; ++i) y[i] ^= x[i - 13]; x = y; y = x; for (int i = 0; i + 17 < 32; ++i) y[i] ^= x[i + 17]; x = y; y = x; for (int i = 5; i < 32; ++i) y[i] ^= x[i - 5]; return y; } int handValue(char c) { if (c == 'R') return 0; if (c == 'S') return 1; if (c == 'P') return 2; return 3; // X } u32 recoverInitialState(const string& t) { array symbolic{}; for (int bit = 0; bit < 32; ++bit) symbolic[bit] = u32(1) << bit; vector equations; equations.reserve(2 * t.size()); for (char c : t) { symbolic = nextSymbolic(symbolic); const int value = handValue(c); equations.push_back(u64(symbolic[0]) | (u64(value & 1) << 32)); equations.push_back(u64(symbolic[1]) | (u64((value >> 1) & 1) << 32)); } array pivotRow; pivotRow.fill(-1); int row = 0; for (int col = 0; col < 32; ++col) { int selected = -1; for (int i = row; i < static_cast(equations.size()); ++i) { if ((equations[i] >> col) & 1ULL) { selected = i; break; } } if (selected == -1) continue; swap(equations[row], equations[selected]); pivotRow[col] = row; for (int i = 0; i < static_cast(equations.size()); ++i) { if (i != row && ((equations[i] >> col) & 1ULL)) { equations[i] ^= equations[row]; } } ++row; } u32 initial = 0; for (int col = 0; col < 32; ++col) { if (pivotRow[col] != -1 && ((equations[pivotRow[col]] >> 32) & 1ULL)) { initial |= u32(1) << col; } } return initial; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); string T; int N; cin >> T >> N; u32 state = recoverInitialState(T); for (int i = 0; i < 100; ++i) state = nextState(state); static constexpr char winningHand[4] = {'X', 'R', 'S', 'P'}; string answer; answer.reserve(N); for (int i = 0; i < N; ++i) { state = nextState(state); answer.push_back(winningHand[state & 3U]); } cout << answer << '\n'; return 0; }