# coding:utf-8 import sys # from itertools import product # # #ume = [0, 0, 1, 3, 6, 11, 21, 42, 85, 171, 342, 683, 1365, 2730, 5461, 10923, 21846, 43691, 87381, 174762, 349525, # 699051, 1398102, 2796203, 5592405, 10000001] ume_i = [0,22, 23, 24, 24, 24, 25, 25, 25, 25, 25] ume_j = [0,1805703, 3611383, 1222795, 7222771, 13222757, 2445581, 8445561, 14445575, 20445563, 26445559] #def popcount(x): # return bin(x).count("1") def popcount(n): n = (n & 0x5555555555555555) + ((n & 0xAAAAAAAAAAAAAAAA) >> 1) n = (n & 0x3333333333333333) + ((n & 0xCCCCCCCCCCCCCCCC) >> 2) n = (n & 0x0F0F0F0F0F0F0F0F) + ((n & 0xF0F0F0F0F0F0F0F0) >> 4) n = (n & 0x00FF00FF00FF00FF) + ((n & 0xFF00FF00FF00FF00) >> 8) n = (n & 0x0000FFFF0000FFFF) + ((n & 0xFFFF0000FFFF0000) >> 16) n = (n & 0x00000000FFFFFFFF) + ((n & 0xFFFFFFFF00000000) >> 32) return n # if N in ume: # print(ume.index(N)) # sys.exit() # else: def solve(): N = int(input()) count = 0 # 100000毎にume # ume_i = [] # ume_j = [] # c = 1000000 p = int(N/1000000) start_i = ume_i[p] start_j = ume_j[p] if p!=0: count = p*1000000-1 x = 0 for i in range(start_i,26): for j in range(start_j,10000000000000): a = bin(j)[2:] if len(a)>i: break if popcount(j)%3==0 and popcount(j)>=3 and a[-1]=='1': count += 1 # ==== # if count == c: # ume_i.append(i) # ume_j.append(j) # c += 1000000 # ==== if count==N: a = '0'*(i-len(a))+a n = a.replace('0', '3').replace('1', '5') x = ''.join(n) x = int(x) print(x) sys.exit() solve()