from __future__ import print_function

def EncodeNegBase(n, b): 
	if n == 0:
		return 
	out = []
	while n != 0:
		n, rem = divmod(n, b)
		if rem < 0:
			n += 1
			rem -= b
		out.append(rem)
	return .join(map(str, out[::-1]))

def DecodeNegBase(nstr, b): 
	if nstr == :
		return 0

	total = 0
	for i, ch in enumerate(nstr[::-1]):
		total += int(ch) * b**i
	return total

if __name__==:

	print ()
	result = EncodeNegBase(10, -2)
	print (result)
	if DecodeNegBase(result, -2) == 10: print ()
	else: print ()

	print ()
	result = EncodeNegBase(146, -3)
	print (result)
	if DecodeNegBase(result, -3) == 146: print ()
	else: print ()

	print ()
	result = EncodeNegBase(15, -10)
	print (result)
	if DecodeNegBase(result, -10) == 15: print ()
	else: print ()