lib C fun strtoll(s : UInt8*, p : UInt8**, b : Int32) : Int64 end class String def to_i64 C.strtoll(self, nil, 10) end end require "big" s = read_line num = s.to_big_i s = s.chars.map &.to_i n = s.size if s.count(s[0]) == n puts s.join exit end p num.gcd (0...n).to_a.combinations(2).map { |(i, j)| 9 * (s[i] - s[j]).abs }.reduce(0) { |i, j| i.gcd(j) }