n = gets.chomp.chars.reverse result = [] n.each_slice(3) {|arr| result << arr.reverse << ',' } puts result.reverse.join("").reverse.chop.reverse