N=gets.chomp.to_i def match(n) # 6 => 9 # 5 => 5 # 4 => 4 # 3 => 7 # 2 => 1 # 1 か 7しかない seven = n % 2 == 1 c = -1 while n > 0 c += 1 n = n >> 1 end puts c ret = 0 for num in 0..c-1 if num == (c-1) and seven ret += 10 ** num * 7 else ret += 10 ** num end end return ret end puts match(N)