from functools import reduce
lis = [(1000, 'M'), (900, 'CM'), (500, 'D'), (400, 'CD'), (100, 'C'), (90, 'XC'), (50, 'L'), (40, 'XL'), (10, 'X'), (9, 'IX'), (5, 'V'), (4, 'IV'), (1, 'I')]
f = lambda num:reduce(lambda x,y:(x[0]%y[0], x[1]+y[1]*(x[0]//y[0])), lis, (num, ''))
numbers = [4100, 2345, 658, 900, 23, 6, 239, 244]
for number in numbers:
print(f"{number} : {f(number)}")
ZnJvbSBmdW5jdG9vbHMgaW1wb3J0IHJlZHVjZQoKbGlzID0gWygxMDAwLCAnTScpLCAoOTAwLCAnQ00nKSwgKDUwMCwgJ0QnKSwgKDQwMCwgJ0NEJyksICgxMDAsICdDJyksICg5MCwgJ1hDJyksICg1MCwgJ0wnKSwgKDQwLCAnWEwnKSwgKDEwLCAnWCcpLCAoOSwgJ0lYJyksICg1LCAnVicpLCAoNCwgJ0lWJyksICgxLCAnSScpXQoKZiA9IGxhbWJkYSBudW06cmVkdWNlKGxhbWJkYSB4LHk6KHhbMF0leVswXSwgeFsxXSt5WzFdKih4WzBdLy95WzBdKSksIGxpcywgKG51bSwgJycpKQoKbnVtYmVycyA9IFs0MTAwLCAyMzQ1LCA2NTgsIDkwMCwgMjMsIDYsIDIzOSwgMjQ0XQoKZm9yIG51bWJlciBpbiBudW1iZXJzOgogIHByaW50KGYie251bWJlcn0gOiB7ZihudW1iZXIpfSIp