#sorry def main s = gets.chomp x = Time.now() def gcd(a,b) if b!=0 then return gcd(b, a%b) else return a end end 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.400 then break end for i in 0..10 do a = rand(0...len) b = rand(0...len) u = (n/(10**a))%10 v = (n/(10**b))%10 n = n + (v-u)*(10**a) + (u-v)*(10**b) g = gcd(g, n) end if g == 1 then break end end puts g end main()