import java.lang.*;
import java.util.*;
public class Main {
static Scanner scanner = new Scanner(System.in);
static int n; // 最大页码
// 将所有可连写的都拆分成n个 可省略一部分组合情况
// 如 III-->I+I+I 即 3-->1+1+1 VII-->V+II-->V+I+I 即 7-->5+2-->5+1+1
// nums 枚举所有组合对应的阿拉伯数字
static int[] nums = {1, 4, 5, 9, 10, 40, 50, 90, 100, 400, 500, 900, 1000};
// words 枚举所有组合对应的罗马数字
static String[] words = {"I", "IV", "V", "IX", "X", "XL", "L", "XC", "C", "CD", "D", "CM", "M"};
// 所有基本字符 升序
static String[] targets = {"I", "V", "X", "L", "C", "D", "M"};
public static void main(String[] args) {
// 读最大页码
n = scanner.nextInt();
// 存页码的罗马数字组合
StringBuilder strbld = new StringBuilder();
// 存所有字符出现的个数
int[] ans = new int[7];
// 页码n~1 逆序枚举
for (int i = n; i >= 1; i--) {
// 页码赋值给k 对每个页码 从大到小枚举words所有的罗马数字
for (int j = nums.length - 1, k = i; k > 0 && j >= 0; j--) {
// 如果k不小于当前罗马数字对应的值 证明该数字可用
if (k >= nums[j]) {
// 考虑连写的情况 所需当前罗马数字的个数应为 (k / nums[j]) 个
// 如 3001 需 3001/1000=3 个M
// 重复添加该罗马数字到StringBuilder
for (int t = k / nums[j]; t > 0; t--) {
strbld.append(words[j]);
}
// 更新k值
k %= nums[j];
}
}
// 转为String类型
String str = strbld.toString();
// 清空原Builder内容
strbld.delete(0, strbld.length());
// 遍历每个基本字符 分别将str中的对应字符替换为"" 相当于删除 则字符串总长度减少
for (int j = 0; j < 7; j++) {
String strNew = str.replace(targets[j], "");
// 替换前后长度差为该字符出现次数
ans[j] += str.length() - strNew.length();
}
}
// 遍历ans输出字符和对应出现次数
for (int i = 0; i < 7; i++) {
if (ans[i] > 0) {
System.out.printf("%s %d\n", targets[i], ans[i]);
}
}
}
}