import sys
sys.stdin = open("input.txt")


data = int(input())
value = data
result = []

while value >= 6:
    result += [value%7]
    value = value//7
result.append(value)

ans = result[::-1]
ans = ' '.join(map(str,ans))
print(ans)


9fa852f7c7cd83dadd870c47f9182ebf67bfe167
<mask token>

<mask token>
while value >= 6:
    result += [value % 7]
    value = value // 7
result.append(value)
<mask token>
print(ans)

<mask token>
sys.stdin = open('input.txt')
data = int(input())
value = data
result = []
while value >= 6:
    result += [value % 7]
    value = value // 7
result.append(value)
ans = result[::-1]
ans = ' '.join(map(str, ans))
print(ans)

import sys
sys.stdin = open('input.txt')
data = int(input())
value = data
result = []
while value >= 6:
    result += [value % 7]
    value = value // 7
result.append(value)
ans = result[::-1]
ans = ' '.join(map(str, ans))
print(ans)

import sys
sys.stdin = open("input.txt")


data = int(input())
value = data
result = []

while value >= 6:
    result += [value%7]
    value = value//7
result.append(value)

ans = result[::-1]
ans = ' '.join(map(str,ans))
print(ans)

