#sorry def main s = gets.chomp x = Time.now() len = s.length if len == 1 then puts s return end g = s.to_i n = g while true y = Time.now() if y-x > 0.700 then break end if g == 1 then break end for i in 0..10 do for j in 0...5 do a = rand(0...len) b = rand(0...len) u = (n % (10**(a+1)) / (10**a)) v = (n % (10**(b+1)) / (10**b)) n = n + ((v-u)*(10**a)) + ((u-v)*(10**b)) end if g != n then g = g.gcd(n) end end end puts g end main()