#!/usr/bin/env python3

def main():
    inp = int(input("Enter number: "))
    while inp != 1:
        if inp%3 == 0:
            print("{0} {1}".format(inp, 0))
            inp = int(inp/3)
        elif (inp+1)%3 == 0:
            print("{0} {1}".format(inp, 1))
            inp += 1
            inp = int(inp/3)
        elif (inp-1)%3 == 0:
            print("{0} {1}".format(inp, -1))
            inp -= 1
            inp = int(inp/3)
    print(inp)



if __name__ == "__main__":
    main()
