#include #include #include #include using namespace std; using ll = long long; constexpr int iINF = 1'000'000'000; constexpr ll llINF = 1'000'000'000'000'000'000; int main () { int N; cin >> N; // 貪欲っぽく見えるけどこういうのは注意。dpしましょ vector balls = { 1, 6, 30, 180, 360, 720, }; vector symbols = { '.', 'o', 'R', 'S', 'M', 'C', }; map inv; for (int i = 0; i < balls.size(); i++) inv[balls[i]] = i; vector dp(N + 1, iINF); vector pre(N + 1); dp[0] = 0; // 配る遷移でやろうね。 for (int i = 0; i < N; i++) { for (int j = 0; j < balls.size(); j++) { if (N < i + balls[j]) continue; if (dp[i] + 1 < dp[i + balls[j]]) { dp[i + balls[j]] = dp[i] + 1; pre[i + balls[j]] = i; } } } // 復元 vector ans; int pos = N; while (0 < pos) { ans.push_back(inv[pos - pre[pos]]); pos = pre[pos]; } sort(ans.begin(), ans.end(), [&](int x, int y) { return balls[y] < balls[x]; }); for (auto i : ans) cout << symbols[i]; cout << "\n"; }