Загрузка данных


ans=[]


for n in range(1,1000):
    x = ""
    i = ""
    q = 0
    y = n
    while n > 0:
        x = x + str(n%3)
        n = n // 3
    x = x[::-1]

    if y % 3 == 0:
        x = x + x[-2:]
    else:
        q = sum(map(int, x))
        q = q * 2
        while q > 0:
            i = i + str(q % 3)
            q = q // 3
        i=str(i)[::-1]
        x = x + i
    r = int(x,3)
    if r > 520 and r % 2 != 0 and r not in ans:
        ans.append(r)
print(min(ans))