You have a description of a lever as string s. We'll represent the string length as record |s|, then the lever looks as a horizontal bar with weights of length |s| - 1 with exactly one pivot. We will assume that the bar is a segment on the Ox axis between points 0 and |s| - 1.

The decoding of the lever description is given below.

  If the i-th character of the string equals "^", that means that at coordinate i there is the pivot under the bar.  If the i-th character of the string equals "=", that means that at coordinate i there is nothing lying on the bar.  If the i-th character of the string equals digit c (1-9), that means that at coordinate i there is a weight of mass c on the bar. 

Your task is, given the lever description, print if it will be in balance or not. Assume that the bar doesn't weight anything. Assume that the bar initially is in balance then all weights are simultaneously put on it. After that the bar either tilts to the left, or tilts to the right, or is in balance.


-----Input-----

The first line contains the lever description as a non-empty string s (3 ≤ |s| ≤ 10^6), consisting of digits (1-9) and characters "^" and "=". It is guaranteed that the line contains exactly one character "^". It is guaranteed that the pivot of the lever isn't located in any end of the lever bar.

To solve the problem you may need 64-bit integer numbers. Please, do not forget to use them in your programs.


-----Output-----

Print "left" if the given lever tilts to the left, "right" if it tilts to the right and "balance", if it is in balance.


-----Examples-----
Input
=^==

Output
balance

Input
9===^==1

Output
left

Input
2==^7==

Output
right

Input
41^52==

Output
balance



-----Note-----

As you solve the problem, you may find the following link useful to better understand how a lever functions: http://en.wikipedia.org/wiki/Lever.

The pictures to the examples:

 [Image] 

 [Image] 

 [Image] 

 $\Delta \Delta \Delta \Delta$

Difficulty: EASY
Tags: Mathematics

Implementation

Starter code:

Solutions:
s = input()
suc = 0
p = 0
kde = 0
for i in range(len(s)):
	c = s[i]
	if c == '^':
		kde = i
for i in range(len(s)):
	c = s[i]
	if '1' <= c <= '9':
		suc += (kde - i) * int(c)
		p += 1
if suc < 0:
	print('right')
elif suc > 0:
	print('left')
else:
	print('balance')


k = input()
g = k.index('^')
(c, f) = (0, 0)
for i in range(len(k)):
	if i < g and k[i] != '=':
		c += int(k[i]) * (g - i)
	elif i > g and k[i] != '=':
		f += int(k[i]) * (i - g)
print('balance') if c == f else print(['left', 'right'][c < f])


class MyApp:

	def __init__(self, s):
		self.s = s

	def build(self):
		a = b = 0
		value = 1
		(left, right) = self.s.split('^')
		for i in left[::-1]:
			if i != '=':
				a += int(i) * value
			value += 1
		value = 1
		for i in right:
			if i != '=':
				b += int(i) * value
			value += 1
		print('balance' if a == b else 'right' if a < b else 'left')
root = MyApp(input())
root.build()


def weight(state):
	state = state.rstrip('=')
	return 0 if len(state) < 1 else sum((int(state[i]) * (i + 1) if state[i] != '=' else 0 for i in range(len(state))))

def main():
	[left, right] = input().split('^')
	left = left[::-1]
	(weight_left, weight_right) = (weight(left), weight(right))
	print('balance' if weight_left == weight_right else 'left' if weight_left > weight_right else 'right')
main()


import os, sys
from io import BytesIO, IOBase

def main():
	s = input().strip()
	x = s.index('^')
	(a, b) = (0, 0)
	for (ind, val) in enumerate(s):
		if val != '=':
			if ind > x:
				b += int(val) * (ind - x)
			elif ind < x:
				a += int(val) * (x - ind)
	if a == b:
		print('balance')
	elif a > b:
		print('left')
	else:
		print('right')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


a = input()
i = 0
r = 0
l = 0
while a[i] != '^':
	i = i + 1
k = i
for j in range(i):
	if a[j] != '=':
		l = l + k * int(a[j])
	k = k - 1
k = 1
i += 1
while i < len(a):
	if a[i] != '=':
		r = r + k * int(a[i])
	i = i + 1
	k = k + 1
if r == l:
	print('balance')
elif l > r:
	print('left')
else:
	print('right')


__author__ = 'runekri3'
lever_str = input()
(left_str, right_str) = lever_str.split('^')
left_str = left_str[::-1]
(left_w, right_w) = (0, 0)
mult = 0
for letter in left_str:
	mult += 1
	if letter != '=':
		left_w += mult * int(letter)
mult = 0
for letter in right_str:
	mult += 1
	if letter != '=':
		right_w += mult * int(letter)
if left_w < right_w:
	print('right')
elif left_w > right_w:
	print('left')
else:
	print('balance')


def main():
	string = input()
	fulcrum = string.index('^')
	mass_left = 0
	mass_right = 0
	for i in range(0, fulcrum):
		if string[i] != '=':
			mass_left += int(string[i]) * (fulcrum - i)
	for i in range(fulcrum + 1, len(string)):
		if string[i] != '=':
			mass_right += int(string[i]) * (i - fulcrum)
	if mass_left == mass_right:
		print('balance')
		return
	if mass_left < mass_right:
		print('right')
		return
	if mass_right < mass_left:
		print('left')
		return

def __starting_point():
	main()
__starting_point()


s = input()
pivot_index = s.find('^')
left_weight = 0
right_weight = 0
for i in range(len(s)):
	if s[i].isdigit():
		if pivot_index - i > 0:
			left_weight += int(s[i]) * (pivot_index - i)
		else:
			right_weight += int(s[i]) * (i - pivot_index)
if left_weight == right_weight:
	print('balance')
elif left_weight > right_weight:
	print('left')
else:
	print('right')


s = input().strip()
l = 0
r = 0
for i in range(len(s)):
	if s[i] == '^':
		p = i
for i in range(len(s)):
	if '1' <= s[i] <= '9':
		if i > p:
			r += int(s[i]) * (i - p)
		else:
			l += int(s[i]) * (p - i)
if l > r:
	print('left')
elif l == r:
	print('balance')
else:
	print('right')


s = input()
ans = 0
for i in range(len(s)):
	if s[i] == '^':
		mul = i
g = 0
for i in range(len(s)):
	if s[i] == '^':
		ans *= -1
		mul = 0
		g = 1
	elif s[i] == '=':
		pass
	else:
		ans += int(s[i]) * mul
	if g:
		mul += 1
	else:
		mul -= 1
if ans == 0:
	print('balance')
elif ans > 0:
	print('right')
else:
	print('left')


s = input()
l = s.find('^')
suml = 0
sumr = 0
for i in range(l):
	if s[i] == '=':
		continue
	suml += (l - i) * int(s[i])
for i in range(l + 1, len(s)):
	if s[i] == '=':
		continue
	sumr += (i - l) * int(s[i])
if suml == sumr:
	print('balance')
elif suml > sumr:
	print('left')
else:
	print('right')


S = input()
digits = [1, 2, 3, 4, 5, 6, 7, 8, 9]
answer = ''
mid = S.find('^')
(digits_sum1, digits_sum2) = (0, 0)
for i in range(mid):
	if S[i].isdigit():
		digits_sum1 += int(S[i]) * (mid - i)
for i in range(mid, len(S)):
	if S[i].isdigit():
		digits_sum2 += int(S[i]) * abs(mid - i)
if digits_sum1 == digits_sum2:
	print('balance')
elif digits_sum1 > digits_sum2:
	print('left')
elif digits_sum2 > digits_sum1:
	print('right')


s = input()
l1 = []
l2 = []
b = s.index('^')
for i in range(len(s)):
	if i < b:
		l1.append(s[i])
	elif i > b:
		l2.append(s[i])
l1.reverse()
t1 = 0
t2 = 0
for i in range(0, len(l1)):
	if l1[i] == '=':
		continue
	else:
		l1[i] = int(l1[i])
		t1 = t1 + (i + 1) * l1[i]
for i in range(0, len(l2)):
	if l2[i] == '=':
		continue
	else:
		l2[i] = int(l2[i])
		t2 = t2 + (i + 1) * l2[i]
if t1 == t2:
	print('balance')
elif t1 > t2:
	print('left')
elif t2 > t1:
	print('right')
else:
	print('no balance')


s = input()
piv = s.index('^')
sum = 0
for i in range(len(s)):
	if s[i].isdigit():
		sum += (i - piv) * int(s[i])
if sum == 0:
	print('balance')
elif sum > 0:
	print('right')
else:
	print('left')


a = input()
(ant, pos) = (0, 0)
h = []
j = -1
used_ant = 0
used_post = 1
ti = 0
while a[ti] != '^':
	ti += 1
for x in range(0, len(a)):
	if j == -1 and a[x] != '^':
		if a[x] != '=':
			ant += int(a[x]) * (ti - used_ant)
			used_ant += 1
		else:
			used_ant += 1
	elif j == 1 and a[x] != '^':
		if a[x] != '=':
			pos += int(a[x]) * used_post
			used_post += 1
		else:
			used_post += 1
	elif a[x] == '^':
		j = 1
if ant == pos:
	print('balance')
elif ant < pos:
	print('right')
else:
	print('left')


s = input()
(e, q, w) = (s.index('^'), 0, 0)
for i in range(e):
	if s[i] != '=':
		q += int(s[i]) * (e - i)
for i in range(e + 1, len(s)):
	if s[i] != '=':
		w += int(s[i]) * (i - e)
print('left' if q > w else 'right' if w > q else 'balance')


str = input()
(a, b) = str.split('^')
(s1, s2) = (0, 0)
for i in range(len(a)):
	if a[i] != '=':
		s1 += (len(a) - i) * int(a[i])
for i in range(len(b)):
	if b[i] != '=':
		s2 += (i + 1) * int(b[i])
if s1 == s2:
	print('balance')
elif s1 > s2:
	print('left')
else:
	print('right')


s = input()
pivot = s.find('^')
value = 0
for i in range(len(s)):
	if s[i].isdigit():
		value += int(s[i]) * (i - pivot)
if value < 0:
	print('left')
elif value == 0:
	print('balance')
else:
	print('right')


s = input()
pivot = s.index('^')
left = s[:pivot]
right = s[pivot + 1:]
left_total = 0
right_total = 0
for l in range(len(left)):
	if left[l] != '=':
		left_total += (pivot - l) * int(left[l])
for r in range(len(right)):
	if right[r] != '=':
		right_total += (r + 1) * int(right[r])
if left_total == right_total:
	print('balance')
elif left_total > right_total:
	print('left')
else:
	print('right')


s = input()
l = len(s)
check = '123456789'
a = s.find('^')
left = 0
right = 0
for i in range(a):
	if s[i] in check:
		left += int(s[i]) * abs(a - i)
for i in range(a, l):
	if s[i] in check:
		right += int(s[i]) * abs(a - i)
if left == right:
	print('balance')
elif left > right:
	print('left')
else:
	print('right')


s = input().replace('=', '0')
fi = list(map(int, list(s[:s.find('^')])))
sec = list(map(int, list(s[s.find('^') + 1:])))
n = len(fi)
fi2 = [fi[i] * (n - i) for i in range(n)]
n = len(sec)
sec2 = [sec[i] * (i + 1) for i in range(n)]
ans = sum(fi2) - sum(sec2)
if ans == 0:
	print('balance')
elif ans < 0:
	print('right')
else:
	print('left')


l = list(input())
indx = l.index('^')
lis = [i for i in range(1, 10)]
l_tq = 0
r_tq = 0
for i in range(indx):
	if l[i] != '=':
		l_tq += int(l[i]) * (indx - i)
for i in range(indx + 1, len(l)):
	if l[i] != '=':
		r_tq += int(l[i]) * (i - indx)
if r_tq == l_tq:
	print('balance')
elif r_tq > l_tq:
	print('right')
else:
	print('left')


n = input()
x = n.index('^')
c = 0
for i in range(len(n)):
	if n[i] != '=' and n[i] != '^':
		c += (x - i) * int(n[i])
if c < 0:
	print('right')
elif c > 0:
	print('left')
else:
	print('balance')


s = input()
for i in range(0, len(s)):
	if s[i] == '^':
		n = i
		break
c = 1
left = 0
for i in range(n - 1, -1, -1):
	if s[i] == '=':
		c += 1
		continue
	left += int(s[i]) * c
	c += 1
c = 1
right = 0
for i in range(n + 1, len(s)):
	if s[i] == '=':
		c += 1
		continue
	right = right + int(s[i]) * c
	c += 1
if left == right:
	print('balance')
elif left > right:
	print('left')
else:
	print('right')


d = input()
m = d.index('^')
m += 1
s = 0
for (i, c) in enumerate(d):
	if c == '^' or c == '=':
		continue
	i += 1
	c = int(c)
	s += c * (i - m)
if s == 0:
	print('balance')
elif s > 0:
	print('right')
else:
	print('left')


X = input()
Left = ''.join(reversed(X[0:X.index('^')]))
Right = X[X.index('^') + 1:]
ValueLeft = sum(((i + 1) * int(Left[i]) if Left[i] != '=' else 0 for i in range(len(Left))))
ValueRight = sum(((i + 1) * int(Right[i]) if Right[i] != '=' else 0 for i in range(len(Right))))
print('left' if ValueLeft > ValueRight else 'right' if ValueRight > ValueLeft else 'balance')


s = input()
index = s.find('^')
ls = []
for (k, c) in enumerate(s):
	if str.isdigit(c):
		ls.append(int(c) * (index - k))
ans = sum(ls)
if ans < 0:
	print('right')
elif ans > 0:
	print('left')
else:
	print('balance')


s = input()
l = len(s)
ind = s.index('^')
s1 = s[:ind]
s2 = s[ind + 1:]
s1 = s1[::-1]
(ris1, ris2) = (0, 0)
for x in range(len(s1)):
	if s1[x].isalnum():
		ris1 += (x + 1) * int(s1[x])
for x in range(len(s2)):
	if s2[x].isalnum():
		ris2 += (x + 1) * int(s2[x])
if ris1 > ris2:
	print('left')
elif ris2 > ris1:
	print('right')
else:
	print('balance')


s = input()
f = 0
(r, l) = (0, 0)
p = s.index('^')
for i in range(len(s)):
	if s[i] == '^':
		f = 1
		continue
	if f:
		if s[i] != '=':
			r += (i - p) * int(s[i])
	elif f == 0:
		if s[i] != '=':
			l += (p - i) * int(s[i])
if r == l:
	print('balance')
elif r > l:
	print('right')
else:
	print('left')


x = input()
x = x.split('^')
l = r = 0
lxl = len(x[0])
lxr = len(x[1])
for i in range(lxl):
	if x[0][i] != '=':
		l += int(x[0][i]) * (lxl - i)
for i in range(lxr):
	if x[1][i] != '=':
		r += int(x[1][i]) * (i + 1)
if l > r:
	print('left')
elif r > l:
	print('right')
else:
	print('balance')


a = input()
t = a.index('^')
t1 = 0
t2 = 0
for i in range(t):
	if ord(a[i]) >= 48 and ord(a[i]) <= 57:
		k = int(a[i]) * (t - i)
		t1 = t1 + k
for i in range(len(a) - 1, t, -1):
	if ord(a[i]) >= 48 and ord(a[i]) <= 57:
		k = int(a[i]) * (i - t)
		t2 = t2 + k
if t2 > t1:
	print('right')
elif t1 > t2:
	print('left')
else:
	print('balance')


s = input().strip()
n = len(s)
i = s.find('^')
left = 0
right = 0
l = i - 1
r = i + 1
while l >= 0 or r < n:
	if l >= 0 and s[l] != '=':
		left += int(s[l]) * (i - l)
		l -= 1
	else:
		l -= 1
	if r < n and s[r] != '=':
		right += int(s[r]) * (r - i)
		r += 1
	else:
		r += 1
if left == right:
	print('balance')
elif left > right:
	print('left')
else:
	print('right')


a = input()
mid = a.index('^')
s = 0
for i in range(len(a)):
	if a[i] != '=' and a[i] != '^':
		v = int(a[i])
		s += v * (i - mid)
if s == 0:
	print('balance')
elif s < 0:
	print('left')
else:
	print('right')


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
readint = lambda : int(sys.stdin.readline().rstrip('\r\n'))
readints = lambda : map(int, sys.stdin.readline().rstrip('\r\n').split())
readstr = lambda : sys.stdin.readline().rstrip('\r\n')
readstrs = lambda : map(str, sys.stdin.readline().rstrip('\r\n').split())
readarri = lambda : [int(_) for _ in sys.stdin.readline().rstrip('\r\n').split()]
readarrs = lambda : [str(_) for _ in sys.stdin.readline().rstrip('\r\n').split()]

def solve():
	s = readstr()
	n = len(s)
	(l, r) = (0, 0)
	start = s.index('^')
	for i in range(0, start):
		if s[i] in '1234567890':
			l += int(s[i]) * abs(i - start)
	for i in range(start + 1, n):
		if s[i] in '1234567890':
			r += int(s[i]) * abs(i - start)
	if l == r:
		print('balance')
	elif l < r:
		print('right')
	else:
		print('left')

def main():
	t = 1
	for _ in range(t):
		solve()
main()


a = list(input())
p = a.index('^')
l = 0
r = 0
for i in range(p):
	if ord(a[i]) >= 48 and ord(a[i]) <= 57:
		l += int(a[i]) * (p - (i + 1) + 1)
for i in range(p + 1, len(a)):
	if ord(a[i]) >= 48 and ord(a[i]) <= 57:
		r += int(a[i]) * (i - p)
if l > r:
	print('left')
elif l < r:
	print('right')
else:
	print('balance')


s = str(input())
for cont in range(0, len(s)):
	if s[cont] == '^':
		pos = cont
		break
left = 0
right = 0
for d in range(0, pos):
	if s[d].isdigit():
		left += int(s[d]) * (pos - d)
for d in range(pos + 1, len(s)):
	if s[d].isdigit():
		right += int(s[d]) * (d - pos)
if left == right:
	print('balance')
elif right > left:
	print('right')
else:
	print('left')


mid = 0

def main():

	def f(a):
		x = []
		for i in range(len(a)):
			if a[i] == '=':
				x.append(0)
			else:
				x.append(int((i + 1) * int(a[i])))
		return sum(x)
	s = input().split('^')
	mid = len(s[0])
	left = list(map(f, [list(reversed(s[0]))]))[0]
	right = list(map(f, [s[1]]))[0]
	if left == right:
		return 'balance'
	elif left < right:
		return 'right'
	return 'left'
print(main())


t = input()
(s, k) = (0, t.find('^'))
for (i, j) in enumerate(t[:k]):
	if j != '=':
		s += int(j) * (k - i)
for (i, j) in enumerate(t[k + 1:], 1):
	if j != '=':
		s -= int(j) * i
if s > 0:
	print('left')
elif s < 0:
	print('right')
else:
	print('balance')


string = list(input())
left = []
right = []
leftTotal = 0
rightTotal = 0
rightSide = False
pivot = -1
for i in range(len(string)):
	if string[i] == '^':
		pivot = i
for i in range(len(string)):
	if '1' <= string[i] <= '9':
		if rightSide == False:
			leftTotal += int(string[i]) * (pivot - i)
		else:
			rightTotal += int(string[i]) * (i - pivot)
if leftTotal > rightTotal:
	print('left')
elif leftTotal < rightTotal:
	print('right')
else:
	print('balance')


s = input()
(left, right) = s.split('^')
left_sum = right_sum = 0
for i in range(-1, -1 - len(left), -1):
	if left[i] != '=':
		left_sum += -i * int(left[i])
for i in range(len(right)):
	if right[i] != '=':
		right_sum += (i + 1) * int(right[i])
if left_sum == right_sum:
	print('balance')
elif left_sum > right_sum:
	print('left')
else:
	print('right')


s = list(input())
t = 0
I = s.index('^')
for i in range(len(s)):
	if s[i] in ['1', '2', '3', '4', '5', '6', '7', '8', '9']:
		t = t + int(s[i]) * (i - I)
if t > 0:
	print('right')
elif t < 0:
	print('left')
else:
	print('balance')


s = input()
s1 = s.replace('=', '0')
a = 0
b = 0
for i in range(len(s)):
	if s[i] == '^':
		c = i
for i in range(len(s)):
	if i < c:
		a += (ord(s1[i]) - 48) * (c - i)
	if i > c:
		b += (ord(s1[i]) - 48) * (i - c)
if a > b:
	print('left')
elif a < b:
	print('right')
else:
	print('balance')


import sys
import math
import collections
import heapq
input = sys.stdin.readline
s = list(input())
n = len(s) - 1
k = s.index('^')
i = k - 1
j = k + 1
(s1, s2) = (0, 0)
while i != -1 or j != n:
	if i != -1:
		if s[i] != '=':
			s1 += (k - i) * int(s[i])
		i -= 1
	if j != n:
		if s[j] != '=':
			s2 += (j - k) * int(s[j])
		j += 1
if s1 > s2:
	print('left')
elif s1 < s2:
	print('right')
else:
	print('balance')


s = str(input())
l = s[:s.find('^')]
r = s[s.find('^') + 1:]
r = r[::-1]
lw = 0
rw = 0
for i in range(len(l)):
	if l[i] != '=':
		lw += int(l[i]) * len(l[i:])
for i in range(len(r)):
	if r[i] != '=':
		rw += int(r[i]) * len(r[i:])
if rw > lw:
	print('right')
elif rw < lw:
	print('left')
else:
	print('balance')


a = input()
t = a.index('^')
(l, r) = (0, 0)
for k in range(t):
	if 49 <= ord(a[k]) <= 57:
		l += int(a[k]) * (t - k)
for w in range(t, len(a)):
	if 49 <= ord(a[w]) <= 57:
		r += int(a[w]) * (w - t)
if l > r:
	print('left')
elif r > l:
	print('right')
else:
	print('balance')


s = input()
length = len(s)
flag = 0
left = 0
right = 0
for i in range(length):
	if s[i] == '^':
		pos = i
		break
for j in range(pos):
	if s[j] != '=':
		left += (pos - j) * int(s[j])
for j in range(pos + 1, length):
	if s[j] != '=':
		right -= (pos - j) * int(s[j])
if left == right:
	print('balance')
elif left > right:
	print('left')
else:
	print('right')


s = input()
p = s.find('^')
b = 0
for i in range(p):
	if s[i] != '=':
		b += (ord(s[i]) - ord('0')) * (p - i)
for i in range(p + 1, len(s)):
	if s[i] != '=':
		b -= (ord(s[i]) - ord('0')) * (i - p)
print('left' if b > 0 else 'right' if b < 0 else 'balance')


n = input()
a = []
for i in range(len(n)):
	if n[i] == '^':
		break
	else:
		a.append(n[i])
a.reverse()
b = []
while i < len(n) - 1:
	i += 1
	if n[i] == '^':
		break
	else:
		b.append(n[i])
f1 = 0
f2 = 0
for i in range(len(a)):
	if a[i] != '=':
		f1 += int(a[i]) * (i + 1)
for i in range(len(b)):
	if b[i] != '=':
		f2 += int(b[i]) * (i + 1)
if f1 == f2:
	print('balance')
elif f1 > f2:
	print('left')
else:
	print('right')


s = input()
sm = 0
for i in range(len(s)):
	if s[i] == '^':
		ind = i
		break
for i in range(ind):
	if s[i] != '=':
		sm += int(s[i]) * (ind - i)
for i in range(ind + 1, len(s)):
	if s[i] != '=':
		sm -= int(s[i]) * (i - ind)
if sm == 0:
	print('balance')
elif sm > 0:
	print('left')
else:
	print('right')


from sys import stdin, stdout
from math import floor, gcd, fabs, factorial, fmod, sqrt, inf, log
from collections import defaultdict as dd, deque
from heapq import merge, heapify, heappop, heappush, nsmallest
from bisect import bisect_left as bl, bisect_right as br, bisect
mod = pow(10, 9) + 7
mod2 = 998244353

def inp():
	return stdin.readline().strip()

def iinp():
	return int(inp())

def out(var, end='\n'):
	stdout.write(str(var) + '\n')

def outa(*var, end='\n'):
	stdout.write(' '.join(map(str, var)) + end)

def lmp():
	return list(mp())

def mp():
	return map(int, inp().split())

def smp():
	return map(str, inp().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(m, val) for j in range(n)]

def remadd(x, y):
	return 1 if x % y else 0

def ceil(a, b):
	return (a + b - 1) // b

def isprime(x):
	if x <= 1:
		return False
	if x in (2, 3):
		return True
	if x % 2 == 0:
		return False
	for i in range(3, int(sqrt(x)) + 1, 2):
		if x % i == 0:
			return False
	return True
s = inp()
ind = s.index('^')
(a1, a2) = (0, 0)
for i in range(ind - 1, -1, -1):
	if s[i] == '=':
		continue
	a1 += (ind - i) * int(s[i])
for i in range(ind + 1, len(s)):
	if s[i] == '=':
		continue
	a2 += (i - ind) * int(s[i])
if a1 > a2:
	print('left')
elif a2 > a1:
	print('right')
else:
	print('balance')


s = input()
l = s.index('^')
(ans1, ans2) = (0, 0)
j = l
for i in range(l):
	if s[i].isdigit():
		ans1 += int(s[i]) * j
	j -= 1
j = 1
for i in range(l + 1, len(s)):
	if s[i].isdigit():
		ans2 += int(s[i]) * j
	j += 1
if ans1 == ans2:
	print('balance')
elif ans1 > ans2:
	print('left')
else:
	print('right')


n = input()
a = 0
b = 0
p = n.index('^')
for i in range(len(n)):
	if i < p and n[i] != '=':
		a += (p - i) * int(n[i])
	if i > p and n[i] != '=':
		b += (i - p) * int(n[i])
res = ['left', 'balance', 'right']
if a < b:
	print(res[2])
elif a == b:
	print(res[1])
else:
	print(res[0])


s = list(input().strip())
piv = s.index('^')
torque = 0
for i in range(len(s)):
	if s[i].isdigit():
		torque += int(s[i]) * (piv - i)
if torque > 0:
	print('left')
elif torque < 0:
	print('right')
else:
	print('balance')


s = list(input())
ind = s.index('^')
rhs = 0
lhs = 0
c = 1
for i in range(ind - 1, -1, -1):
	if s[i] != '=':
		lhs += c * int(s[i])
	c += 1
d = 1
for j in range(ind + 1, len(s)):
	if s[j] != '=':
		rhs += d * int(s[j])
	d += 1
if lhs == rhs:
	print('balance')
elif lhs > rhs:
	print('left')
else:
	print('right')


__author__ = 'asmn'
s = input()
pivot = s.find('^')
res = sum(map(lambda i_x: int(i_x[1]) * (i_x[0] - pivot) if i_x[1].isdigit() else 0, enumerate(s)))
print('left' if res < 0 else 'right' if res > 0 else 'balance')


S = input()
mid = S.find('^')
(digits_sum1, digits_sum2) = (0, 0)
for i in range(mid):
	if S[i].isdigit():
		digits_sum1 += int(S[i]) * (mid - i)
for i in range(mid, len(S)):
	if S[i].isdigit():
		digits_sum2 += int(S[i]) * abs(mid - i)
if digits_sum1 == digits_sum2:
	print('balance')
elif digits_sum1 > digits_sum2:
	print('left')
elif digits_sum2 > digits_sum1:
	print('right')


lever = input()
i = 0
ind = lever.index('^')
(arr, brr) = ([], [])
for i in range(ind):
	if lever[i].isdigit():
		arr.append(int(lever[i]) * abs(i - ind))
for i in range(ind, len(lever)):
	if lever[i].isdigit():
		brr.append(int(lever[i]) * abs(i - ind))
if sum(arr) > sum(brr):
	print('left')
elif sum(arr) < sum(brr):
	print('right')
else:
	print('balance')


s = input()
l = 0
r = 0
if s[0] == '^':
	print('right')
elif s[len(s) - 1] == '^':
	print('left')
else:
	g = s.index('^')
	for i in range(g):
		if s[i] != '=':
			l += int(s[i]) * (g - i)
	for i in range(g + 1, len(s)):
		if s[i] != '=':
			r += int(s[i]) * (i - g)
	if l > r:
		print('left')
	elif r > l:
		print('right')
	else:
		print('balance')


s = input()
pivot = s.index('^')
left = 0
right = 0
for i in range(pivot):
	if s[i] != '=':
		left += int(s[i]) * (pivot - i)
for i in range(pivot + 1, len(s)):
	if s[i] != '=':
		right += int(s[i]) * (i - pivot)
if left > right:
	print('left')
elif left < right:
	print('right')
else:
	print('balance')


s = input()
sum = 0
for i in range(len(s)):
	if s[i] == '^':
		pivot = i
		break
for i in range(len(s)):
	if s[i] > '0' and s[i] <= '9':
		sum += (i - pivot) * int(s[i])
if sum == 0:
	print('balance')
elif sum < 0:
	print('left')
else:
	print('right')


s = input()
c = s.find('^')
total = sum((int(w) * (c - i) for (i, w) in enumerate(s) if w.isdigit()))
print('left' if total > 0 else 'right' if total < 0 else 'balance')


import sys
import math
import bisect
import itertools
import random
import re

def main():
	s = input()
	n = len(s)
	A = []
	for i in range(n):
		if s[i] == '^':
			pivot = i
	val = 0
	for i in range(n):
		if s[i].isdigit():
			val += (ord(s[i]) - ord('0')) * (i - pivot)
	if val == 0:
		print('balance')
	elif val < 0:
		print('left')
	elif val > 0:
		print('right')
main()


s = input('')
index = s.index('^')
l = []
i = index - 1
count = 0
while i >= 0:
	count += 1
	if s[i] >= '1' and s[i] <= '9':
		l.append([s[i], count])
	i -= 1
l1 = []
for j in range(index + 1, len(s)):
	if s[j] >= '1' and s[j] <= '9':
		l1.append([s[j], j - index])
sum1 = 0
sum2 = 0
for (k, k1) in l:
	sum1 += int(k) * k1
for (k, k1) in l1:
	sum2 += int(k) * k1
if sum1 > sum2:
	print('left')
elif sum1 == sum2:
	print('balance')
else:
	print('right')


s = input()
f = s.index('^')
left = 0
right = 0
for i in range(f - 1, -1, -1):
	if s[i] == '=':
		pass
	else:
		left += abs(f - i) * int(s[i])
for i in range(f + 1, len(s)):
	if s[i] == '=':
		pass
	else:
		right += abs(i - f) * int(s[i])
if left > right:
	print('left')
elif right > left:
	print('right')
else:
	print('balance')


patron = input()
leftWeights = []
rightWeights = []
shouldAddOnLeft = True
for val in patron:
	if val == '^':
		shouldAddOnLeft = False
	else:
		weight = 0
		if val != '=':
			weight = int(val)
		(leftWeights if shouldAddOnLeft else rightWeights).append(weight)
leftWeightsSum = 0
rightWeightsSum = 0
for i in range(len(leftWeights)):
	leftWeightsSum += (len(leftWeights) - i) * leftWeights[i]
for i in range(len(rightWeights)):
	rightWeightsSum += (i + 1) * rightWeights[i]
if leftWeightsSum == rightWeightsSum:
	print('balance')
elif leftWeightsSum < rightWeightsSum:
	print('right')
else:
	print('left')


s = input()
cnt = s.index('^')
(left, right) = (0, 0)
for i in s:
	if i == '^':
		break
	if i == '=':
		cnt -= 1
		continue
	left += int(i) * cnt
	cnt -= 1
cnt = 1
for i in range(s.index('^') + 1, len(s)):
	if s[i] == '=':
		cnt += 1
		continue
	right += int(s[i]) * cnt
	cnt += 1
if right == left:
	print('balance')
if right > left:
	print('right')
if left > right:
	print('left')


s = input()
s = s.split('^')
f1 = 0
f2 = 0
c1 = len(s[0]) + 1
c2 = 0
for i in s[0]:
	c1 -= 1
	if i != '=':
		f1 += int(i) * c1
for j in s[1]:
	c2 += 1
	if j != '=':
		f2 += int(j) * c2
if f1 > f2:
	print('left')
elif f2 > f1:
	print('right')
else:
	print('balance')


m = input()
n = len(m)
(k, o) = (0, 0)
for i in range(n):
	if m[i] == '^':
		l = i
for i in range(l):
	if m[i].isdigit():
		k += int(m[i]) * (l - i)
for i in range(l, n):
	if m[i].isdigit():
		o += int(m[i]) * (i - l)
if k == o:
	print('balance')
elif k > o:
	print('left')
else:
	print('right')


lever = input()
arr = lever.split('^')
leftArr = arr[0]
rightArr = arr[1]
totalLeft = 0
totalRight = 0
result = 'balance'
for i in range(0, len(leftArr)):
	if leftArr[i].isdigit():
		totalLeft += int(leftArr[i]) * len(leftArr[i:len(leftArr)])
for i in range(0, len(rightArr)):
	if rightArr[i].isdigit():
		totalRight += int(rightArr[i]) * len(rightArr[0:i + 1])
if totalLeft > totalRight:
	result = 'left'
elif totalRight > totalLeft:
	result = 'right'
print(result)


s = list(input())
piv = 0
left_w = 0
right_w = 0
for i in range(len(s)):
	if s[i] == '^':
		piv = i
		break
for i in range(len(s)):
	if i <= piv:
		try:
			left_w += int(s[i]) * abs(piv - i)
		except:
			pass
	else:
		try:
			right_w += int(s[i]) * abs(piv - i)
		except:
			pass
if left_w > right_w:
	print('left')
elif left_w < right_w:
	print('right')
else:
	print('balance')


(a, b) = input().replace('=', '0').split('^')
a = a[::-1]
t = len(b) - len(a)
if t > 0:
	a += '0' * t
if t < 0:
	b += '0' * -t
k = sum(((int(a[i]) - int(b[i])) * (i + 1) for i in range(len(a))))
print('right' if k < 0 else ['balance', 'left'][k > 0])


s = input()
bpoint = s.split('^')
leftT = 0
rightT = 0
leftLen = len(bpoint[0])
for (index, i) in enumerate(bpoint[0]):
	if i != '=':
		leftT += (leftLen - index) * int(i)
for (index, i) in enumerate(bpoint[1]):
	if i != '=':
		rightT += (index + 1) * int(i)
if leftT > rightT:
	print('left')
elif rightT > leftT:
	print('right')
else:
	print('balance')


r = input()
r = r.replace('=', '0')
(left, right) = r.split('^')
left = left[::-1]
getsum = lambda arr: sum([int(arr[i]) * (i + 1) for i in range(len(arr))])
lim = getsum(left) - getsum(right)
if lim > 0:
	print('left')
elif lim == 0:
	print('balance')
else:
	print('right')


s = input()
p = s.index('^')
f = 0
for i in range(len(s)):
	if s[i] == '1':
		f = f - (p - i) * 1
	elif s[i] == '2':
		f = f - (p - i) * 2
	elif s[i] == '3':
		f = f - (p - i) * 3
	elif s[i] == '4':
		f = f - (p - i) * 4
	elif s[i] == '5':
		f = f - (p - i) * 5
	elif s[i] == '6':
		f = f - (p - i) * 6
	elif s[i] == '7':
		f = f - (p - i) * 7
	elif s[i] == '8':
		f = f - (p - i) * 8
	elif s[i] == '9':
		f = f - (p - i) * 9
if f < 0:
	print('left')
elif f > 0:
	print('right')
else:
	print('balance')


s = input()
o = s.find('^')
a = list((int(s[i]) if s[i].isdigit() else 0 for i in range(len(s))))
summa = 0
for i in range(len(s)):
	summa += (i - o) * a[i]
if summa < 0:
	print('left')
elif summa == 0:
	print('balance')
else:
	print('right')


s = input()
n = len(s)
tot = 0
count = 0
(l, r) = (0, 0)
for i in range(n):
	if s[i] not in '^=':
		tot += i * int(s[i])
		count += int(s[i])
for i in range(n):
	if s[i] == '^':
		l = i
		break
for i in range(n - 1, -1, -1):
	if s[i] == '^':
		r = i
		break
if count == 0:
	print('balance')
elif tot / count < l:
	print('left')
elif tot / count > r:
	print('right')
else:
	print('balance')


s = input().split('^')
s[0] = s[0][::-1]
m = lambda k: sum(((ord(s[k][i]) - ord('0')) * (i + 1) for i in range(len(s[k])) if s[k][i] != '='))
(a, b) = (m(0), m(1))
print('left' if a > b else 'right' if a < b else 'balance')


s = input()
p = s.find('^')
r = 0
for (k, c) in enumerate(s):
	if str.isdigit(c):
		r += int(c) * (p - k)
if r == 0:
	print('balance')
elif r > 0:
	print('left')
else:
	print('right')


s = input()
p = s
s = s.split('^')
mid = len(s[0])
sumi = 0
for i in range(len(p)):
	val_i = 0
	if p[i].isnumeric():
		val_i = int(p[i])
	if p[i] != '=' and p[i] != '^':
		sumi += val_i * (i - mid)
if sumi > 0:
	print('right')
elif sumi < 0:
	print('left')
else:
	print('balance')


s = input()
l = -1
r = -1
digl = {}
digr = {}
lever = 0
for i in range(len(s)):
	if s[i].isdigit() and lever == 0:
		l = i
		digl[i + 1] = s[i]
	elif s[i].isdigit() and lever != 0:
		r = i
		digr[i + 1] = s[i]
	elif s[i] == '^':
		lever = i
tl = 0
tr = 0
for e in digl:
	tl += (lever + 1 - int(e)) * int(digl[e])
for e in digr:
	tr += (int(e) - lever - 1) * int(digr[e])
if tl > tr:
	print('left')
elif tl < tr:
	print('right')
else:
	print('balance')


from sys import stdin
x = str(stdin.readline())
x = [x for x in x]
x.pop()
mid = x.index('^')
ans = 0
for i in range(len(x)):
	if x[i] != '^' and x[i] != '=':
		if i < mid:
			ans += int(x[i]) * (mid - i)
		else:
			ans -= int(x[i]) * (i - mid)
if ans > 0:
	print('left')
elif ans < 0:
	print('right')
else:
	print('balance')


s = input()
f = 0
an = 0
x = 0
p = s.index('^') + 1
nt = 0
for i in s:
	nt += 1
	x = abs(p - nt)
	if i == '^':
		f = 1
		x = 0
	if f == 0:
		if i != '^' and i != '=':
			an += int(i) * x
	elif i != '^' and i != '=':
		an -= int(i) * x
if an == 0:
	print('balance')
elif an > 0:
	print('left')
else:
	print('right')


def weight(s):
	(w, i) = (0, 1)
	for c in s:
		if c != '=':
			w += i * int(c)
		i += 1
	return w

def main():
	line = input()
	(l, r) = line.split('^')
	l = weight(l[::-1])
	r = weight(r)
	if l > r:
		print('left')
	elif l < r:
		print('right')
	else:
		print('balance')
main()


import sys
import math
instr = sys.stdin.readline().split('^')
ll = len(instr[0])
lr = len(instr[1]) - 1
vlmax = max(ll, lr)
kl = [0] * vlmax
kr = [0] * vlmax
for i in range(ll - 1, -1, -1):
	if instr[0][i] != '=':
		kl[i - ll] = int(instr[0][i])
for i in range(lr):
	if instr[1][i] != '=':
		kr[i] = int(instr[1][i])
res = 0
kl = kl[::-1]
for i in range(vlmax):
	res += kl[i] * (i + 1) - kr[i] * (i + 1)
if res < 0:
	print('right')
elif res > 0:
	print('left')
elif res == 0:
	print('balance')


def lever(s):
	for i in range(len(s)):
		if s[i] == '^':
			pivot = i
			break
	left = pivot - 1
	right = pivot + 1
	sum_left = 0
	sum_right = 0
	c_left = 1
	c_right = 1
	while left >= 0:
		if s[left] != '=':
			sum_left += int(s[left]) * c_left
		left = left - 1
		c_left += 1
	while right < len(s):
		if s[right] != '=':
			sum_right += int(s[right]) * c_right
		right = right + 1
		c_right += 1
	if sum_left > sum_right:
		print('left')
	elif sum_left < sum_right:
		print('right')
	else:
		print('balance')
s = input('')
lever(list(s))


(s1, s2) = map(str, input().split('^'))
(l1, l2) = (0, 0)
for i in range(len(s1)):
	if s1[i].isdigit():
		l1 += int(s1[i]) * (len(s1) - i)
for i in range(len(s2)):
	if s2[i].isdigit():
		l2 += int(s2[i]) * (i + 1)
if l1 == l2:
	print('balance')
elif l1 > l2:
	print('left')
else:
	print('right')


def lever(lever_description_str: str) -> str:
	left_balance = 0
	right_balance = 0
	pivot_pos = lever_description_str.find('^')
	for i in range(len(lever_description_str)):
		if i < pivot_pos and lever_description_str[i] != '=':
			left_balance += (pivot_pos - i) * int(lever_description_str[i])
		elif i > pivot_pos and lever_description_str[i] != '=':
			right_balance += (i - pivot_pos) * int(lever_description_str[i])
	if left_balance < right_balance:
		return 'right'
	elif left_balance > right_balance:
		return 'left'
	else:
		return 'balance'
lever_description = input()
print(lever(lever_description))


from itertools import zip_longest as zl
(a, b) = input().replace('=', '0').split('^')
(ca, cb, counter) = (0, 0, 1)
for (i, j) in zl(reversed(a), b, fillvalue=0):
	ca += int(i) * counter
	cb += int(j) * counter
	counter += 1
print(('left', 'balance', 'right')[(cb >= ca) + (cb > ca)])


lever = input()
pivot = lever.find('^')
left = 0
for i in range(pivot):
	if lever[i] != '=':
		w = int(lever[i])
		left += w * (pivot - i)
right = 0
for i in range(pivot + 1, len(lever)):
	if lever[i] != '=':
		w = int(lever[i])
		right += w * (i - pivot)
if right > left:
	print('right')
elif left > right:
	print('left')
else:
	print('balance')


s = input()
pi = s.index('^')
l = r = flag = 0
for (ind, i) in enumerate(s):
	if i == '^':
		flag = 1
	if i.isdigit():
		if not flag:
			l += (pi - ind) * int(i)
		else:
			r += (ind - pi) * int(i)
if l > r:
	print('left')
elif r > l:
	print('right')
else:
	print('balance')


S = input()
A = {}
pivot = -1
for i in range(len(S)):
	if S[i] == '^':
		pivot = i
	elif S[i] != '=':
		A[i] = int(S[i])
left = 0
right = 0
for key in A:
	w = A[key] * (pivot - key)
	if w > 0:
		left += w
	else:
		right -= w
if left == right:
	print('balance')
elif left > right:
	print('left')
else:
	print('right')


def weight(side):
	res = 0
	pos = 1
	for char in side:
		if char != '=':
			res += int(char) * pos
		pos += 1
	return res
(lefts, rights) = input().split('^')
left_weight = weight(lefts[::-1])
right_weight = weight(rights)
if left_weight > right_weight:
	print('left')
elif right_weight > left_weight:
	print('right')
else:
	print('balance')


def solve(s):
	f_right = 0
	f_left = 0
	is_left = True
	e = s.find('^')
	for (i, c) in enumerate(s):
		if c == '^':
			is_left = False
			continue
		if c == '=':
			continue
		if is_left:
			f_left += (e - i) * int(c)
		else:
			f_right += (i - e) * int(c)
	if f_left > f_right:
		return 'left'
	if f_right > f_left:
		return 'right'
	return 'balance'

def main():
	s = input()
	print(solve(s))
main()


a = input()
a = a.replace('=', '0')
(a, b) = a.split('^')
lt = 0
rt = 0
for i in range(len(b)):
	rt += int(b[i]) * (i + 1)
lena = len(a)
for i in range(lena):
	lt += int(a[lena - 1 - i]) * (i + 1)
if lt > rt:
	print('left')
elif rt > lt:
	print('right')
else:
	print('balance')


barra = input()
x = 0
izq = 0
der = 0
for k in range(0, len(barra)):
	if barra[k] == '^':
		pp = k
for k in range(0, pp):
	if barra[k] != '=':
		izq += int(barra[k]) * (pp - k)
for k in range(pp + 1, len(barra)):
	if barra[k] != '=':
		der += int(barra[k]) * (pp - k)
if izq + der > 0:
	print('left')
elif izq + der == 0:
	print('balance')
else:
	print('right')


s = input()
n = len(s)
(x, y) = (0, 0)
z = s.index('^')
for i in range(n):
	if s[i].isdigit():
		x += int(s[i]) * (i - z)
if x == 0:
	print('balance')
elif x < 0:
	print('left')
else:
	print('right')


a = input()
p = a.index('^')
c = sum(((i - p) * int(y) for (i, y) in enumerate(a) if y.isdigit()))
print([['balance', 'right'][c > 0], 'left'][c < 0])


s = input()
l = len(s)
m = 0
c = []
i = []
sum = 0
for x in range(l):
	if s[x] == '^':
		m = x
	elif s[x] == '=':
		pass
	else:
		c.append(int(s[x]))
		i.append(x)
for y in range(len(c)):
	sum = sum + c[y] * (m - i[y])
if sum > 0:
	print('left')
elif sum < 0:
	print('right')
else:
	print('balance')


s = input()
(a, b) = s.split('^')
resa = 0
resb = 0
for i in range(len(a) - 1, -1, -1):
	if a[i] == '=':
		continue
	resa += int(a[i]) * (len(a) - i)
for i in range(len(b)):
	if b[i] == '=':
		continue
	resb += int(b[i]) * (i + 1)
print('balance' if resa == resb else 'left' if resa > resb else 'right')


a = input()
x = a.index('^')
c = 0
for i in range(len(a)):
	if a[i] in ['^', '=']:
		continue
	c += int(a[i]) * (i - x)
print('right' if c > 0 else 'left' if c < 0 else 'balance')


inputs = input()
x = inputs.find('^')
sum = 0
for (index, chara) in enumerate(inputs):
	if index < x and (not (chara == '=' or chara == '^')):
		sum = sum + int(chara) * (index - x)
	elif index > x and (not (chara == '=' or chara == '^')):
		sum = sum - int(chara) * (x - index)
if sum < 0:
	print('left')
elif sum > 0:
	print('right')
else:
	print('balance')


s = input()
n = len(s)
k = 0
for i in range(n):
	if s[i] == '^':
		k = i + 1
		break
left = 0
right = 0
for i in range(n):
	if s[i] >= '1' and s[i] <= '9':
		if k - (i + 1) > 0:
			left = left + int(s[i]) * (k - i - 1)
		else:
			right += int(s[i]) * abs(k - i - 1)
if left > right:
	print('left')
elif right > left:
	print('right')
else:
	print('balance')


sum = 0
seq = input()
ind = seq.index('^')
for i in range(len(seq)):
	if seq[i].isdigit():
		sum += (ind - i) * int(seq[i])
if sum == 0:
	print('balance')
elif sum > 0:
	print('left')
else:
	print('right')


n = input()
z = n.index('^')
n = list(n)
list1 = n[:z]
list2 = n[z + 1:]
t1 = 0
t2 = 0
list1.reverse()
for i in range(len(list1)):
	if list1[i] != '=':
		t1 += int(list1[i]) * (i + 1)
for i in range(len(list2)):
	if list2[i] != '=':
		t2 += int(list2[i]) * (i + 1)
if t1 > t2:
	print('left')
elif t1 < t2:
	print('right')
else:
	print('balance')


string = input().split('^')
(left, right) = (0, 0)
for i in range(len(string[0])):
	if string[0][i] in '123456789':
		left += (len(string[0]) - i) * int(string[0][i])
for i in range(0, len(string[1])):
	if string[1][i] in '123456789':
		right += (i + 1) * int(string[1][i])
if left == right:
	print('balance')
elif left > right:
	print('left')
else:
	print('right')


s = input()
n = len(s)
left = 0
right = 0
p = s.index('^')
l = []
r = []
for i in range(0, p):
	l.append(s[i])
for i in range(p + 1, n):
	r.append(s[i])
for i in range(0, len(l)):
	if l[i] != '=':
		left = left + int(l[i]) * (p - i)
for i in range(0, len(r)):
	if r[i] != '=':
		ind = i + 1
		right += int(r[i]) * ind
if left > right:
	print('left')
elif right > left:
	print('right')
else:
	print('balance')


s = input()
l = ['1', '2', '3', '4', '5', '6', '7', '8', '9']
left = 0
right = 0
k = s.index('^')
for j in range(k):
	if s[j] in l:
		left += int(s[j]) * (k - j)
for x in range(k, len(s)):
	if s[x] in l:
		right += int(s[x]) * (x - k)
if left == right:
	print('balance')
if left > right:
	print('left')
if right > left:
	print('right')


s = input()
l = '123456789'
p = s.index('^')
(a, b, c) = (0, 0, 0)
for i in range(p - 1, -1, -1):
	c = c + 1
	if s[i] in l:
		a = a + int(s[i]) * c
c = 0
for i in range(p + 1, len(s)):
	c = c + 1
	if s[i] in l:
		b = b + int(s[i]) * c
if a > b:
	print('left')
elif b > a:
	print('right')
else:
	print('balance')


s = input()
r = s.index('^')
sum = 0
for i in range(len(s)):
	if s[i] != '=' and s[i] != '^':
		sum += int(s[i]) * (i - r)
if sum < 0:
	print('left')
elif sum > 0:
	print('right')
else:
	print('balance')


a = input().strip()
n = len(a)
c = a.index('^')
(l, r) = (0, 0)
for i in range(c):
	if a[i].isdigit():
		l += (c - i) * int(a[i])
for i in range(c + 1, n):
	if a[i].isdigit():
		r += (i - c) * int(a[i])
if l == r:
	print('balance')
elif l > r:
	print('left')
else:
	print('right')


s = input()
pos = s.find('^')
balance = 0
for i in range(pos):
	if s[i] != '=':
		balance += int(s[i]) * (pos - i)
for i in range(pos + 1, len(s)):
	if s[i] != '=':
		balance -= int(s[i]) * (i - pos)
if balance > 0:
	print('left')
elif balance < 0:
	print('right')
else:
	print('balance')


def weight(s):
	w = 0
	for (i, x) in enumerate(s):
		if x != '=':
			w += (i + 1) * int(x)
	return w
(l, r) = input().strip().split('^')
(a, b) = (weight(l[::-1]), weight(r))
if a == b:
	print('balance')
elif a < b:
	print('right')
else:
	print('left')


lever = input()
bp = 0
lweights = []
rweights = []
ltw = 0
rtw = 0
numbers = ['1', '2', '3', '4', '5', '6', '7', '8', '9']
for i in range(0, len(lever)):
	if lever[i] == '^':
		bp = i
		break
for i in range(0 - bp, len(lever) - bp):
	if lever[i + bp] in numbers:
		if i < 0:
			lweights.append(int(lever[i + bp]) * (i * -1))
		else:
			rweights.append(int(lever[i + bp]) * i)
for i in range(0, len(lweights)):
	ltw += lweights[i]
for i in range(0, len(rweights)):
	rtw += rweights[i]
if ltw < rtw:
	print('right')
elif rtw < ltw:
	print('left')
else:
	print('balance')


s = input()
sumleft = 0
sumrigth = 0
sumtemp = 0
pressed = 0
step = 1
for a in s:
	if a == '^':
		pressed = 1
		step = 1
	else:
		if a == '=':
			a = 0
		else:
			a = int(a)
		if pressed == 0:
			sumleft += sumtemp + a
			sumtemp += a
		if pressed == 1:
			sumrigth += step * a
			step = step + 1
if sumleft == sumrigth:
	print('balance')
if sumleft > sumrigth:
	print('left')
if sumleft < sumrigth:
	print('right')


s = input()
l = len(s)
i = 0
while i < l:
	if s[i] == '^':
		break
	i = i + 1
n = i + 1
s_r = 0
while n < l:
	if s[n] != '=':
		s_r = s_r + int(s[n]) * (n - i)
	n = n + 1
m = i - 1
s_l = 0
while m >= 0:
	if s[m] != '=':
		s_l = s_l + int(s[m]) * (i - m)
	m = m - 1
if s_l > s_r:
	print('left')
elif s_r > s_l:
	print('right')
else:
	print('balance')


s = input()
for i in range(len(s)):
	if s[i] == '^':
		p = i
pl = 1
sl = 0
while p - pl >= 0:
	if s[p - pl] != '=':
		sl += pl * int(s[p - pl])
	pl += 1
pr = 1
sr = 0
while p + pr < len(s):
	if s[p + pr] != '=':
		sr += pr * int(s[p + pr])
	pr += 1
if sr == sl:
	print('balance')
elif sr > sl:
	print('right')
else:
	print('left')


x = input()
ind = x.index('^')
w1 = x[0:ind]
w2 = x[ind + 1:]
left = 0
right = 0
for i in range(0, ind):
	if x[i] == '=':
		left += 0
	else:
		left += int(x[i]) * (ind - i)
for j in range(ind + 1, len(x)):
	if x[j] == '=':
		right += 0
	else:
		right += int(x[j]) * (j - ind)
if left > right:
	print('left')
if left < right:
	print('right')
if left == right:
	print('balance')


reg = input()
a = reg.index('^')
sum = 0
for i in range(0, len(reg)):
	if reg[i:i + 1] != '^' and reg[i:i + 1] != '=':
		sum += (a - i) * int(reg[i:i + 1])
if sum == 0:
	print('balance')
elif sum > 0:
	print('left')
else:
	print('right')


s = str(input())
m = s.find('^')
left_wt = 0
right_wt = 0
for i in range(m):
	if s[i] == '=':
		left_wt += 0
	else:
		left_wt = left_wt + (m - i) * int(s[i])
for j in range(m + 1, len(s)):
	if s[j] == '=':
		right_wt += 0
	else:
		right_wt = right_wt + (j - m) * int(s[j])
if left_wt > right_wt:
	print('left')
if right_wt > left_wt:
	print('right')
if right_wt == left_wt:
	print('balance')


lst = list(input())
l = 0
r = 0
j = 0
while lst[j] != '^':
	j += 1
z = j
for i in range(j):
	if lst[i] == '=':
		pass
	else:
		l += int(lst[i]) * z
	z -= 1
z = 1
for i in range(j + 1, len(lst)):
	if lst[i] == '=':
		pass
	else:
		r += int(lst[i]) * z
	z += 1
if r > l:
	print('right')
elif l > r:
	print('left')
else:
	print('balance')


n = input()
N = n.split('^')
L = N[0][::-1]
R = N[1]
l = len(L)
SL = 0
i = 1
while i <= l:
	if L[i - 1] != '=':
		SL += i * int(L[i - 1])
	i += 1
r = len(R)
SR = 0
j = 1
while j <= r:
	if R[j - 1] != '=':
		SR += j * int(R[j - 1])
	j += 1
if SL > SR:
	print('left')
elif SL < SR:
	print('right')
else:
	print('balance')


s = str(input(''))
s = list(s)
p = s.index('^')
l = s[0:p:1]
l = l[::-1]
r = s[p + 1:]
sl = sr = 0
for i in range(len(l)):
	if l[i] != '=':
		sl = sl + (i + 1) * int(l[i])
for i in range(len(r)):
	if r[i] != '=':
		sr = sr + (i + 1) * int(r[i])
if sl > sr:
	print('left')
elif sr > sl:
	print('right')
else:
	print('balance')


lis = list(input())
tot = []
sum = 0
for i in range(0, len(lis)):
	if lis[i] == '^':
		mid = i
	elif lis[i].isnumeric():
		tot.append(i)
for k in tot:
	sum = sum + int(lis[k]) * (k - mid)
if sum == 0:
	print('balance')
elif sum < 0:
	print('left')
else:
	print('right')


(s1, s2) = input().split('^')
s1 = s1[::-1]
l1 = sum([(i + 1) * int(s1[i]) for i in range(len(s1)) if s1[i] != '='])
l2 = sum([(i + 1) * int(s2[i]) for i in range(len(s2)) if s2[i] != '='])
print('balance' if l1 == l2 else 'left' if l1 > l2 else 'right')


s = input()
sum = 0
mid = s.index('^')
for i in range(len(s)):
	if s[i] == '=' or s[i] == '^':
		continue
	else:
		sum += int(s[i]) * (i - mid)
if sum > 0:
	print('right')
elif sum < 0:
	print('left')
else:
	print('balance')


import math
s = str(input())
left = 0
right = 0
t = 0
y = 0
r = '123456789'
for i in range(len(s)):
	if s[i] == '^':
		y = i
for i in range(y + 1, len(s)):
	if s[i] in r:
		right += (i - y) * int(s[i])
for i in range(y - 1, -1, -1):
	if s[i] in r:
		left += (y - i) * int(s[i])
if left == right:
	print('balance')
elif right > left:
	print('right')
else:
	print('left')


def sumValues(x):
	suma = 0
	for i in range(len(x)):
		if x[i] != '=':
			suma += int(x[i]) * (i + 1)
	return suma
s = input().split('^')
s[0] = s[0][::-1]
if sumValues(s[0]) > sumValues(s[1]):
	print('left')
elif sumValues(s[0]) == sumValues(s[1]):
	print('balance')
else:
	print('right')


s = input()
m = s.index('^')
f = lambda x: int(x) if x not in ['=', '^'] else 0
k = sum((f(s[i]) * (i - m) for i in range(len(s))))
print([['left', 'right'][0 < k], 'balance'][k == 0])


s = input().strip()
n = len(s)
z = s.index('^')
a = [0] * n
for i in range(n):
	if 48 <= ord(s[i]) <= 57:
		a[i] = int(s[i]) * abs(z - i)
for i in range(1, n):
	a[i] = a[i] + a[i - 1]
if a[z] == a[-1] - a[z]:
	print('balance')
elif a[z] > a[-1] - a[z]:
	print('left')
else:
	print('right')


s = input()
mid = s.index('^')
l = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '0']
sum = 0
for i in range(len(s)):
	if s[i] in l:
		value = int(s[i])
	else:
		value = 0
	sum = sum + value * (i - mid)
if sum == 0:
	print('balance')
elif sum < 0:
	print('left')
else:
	print('right')


(n, m) = map(str, input().split('^'))
l = list(n)
w = list(m)
s = 0
r = 0
p = '1234567890'
for i in range(len(l)):
	if l[len(l) - 1 - i] in p:
		s += int(l[len(l) - 1 - i]) * (i + 1)
for i in range(len(w)):
	if w[i] in p:
		r += int(w[i]) * (i + 1)
if s > r:
	print('left')
elif r > s:
	print('right')
elif r == s:
	print('balance')


a = list(input())
n = len(a)
mLeft = 0
mRight = 0
pos = a.index('^')
for i in range(pos + 1, n):
	if a[i] != '=':
		mRight += int(a[i]) * (i - pos)
for i in range(pos - 1, -1, -1):
	if a[i] != '=':
		mLeft += int(a[i]) * (pos - i)
if mLeft > mRight:
	print('left')
elif mRight > mLeft:
	print('right')
else:
	print('balance')


s = input()
(left, right) = s.split('^')
(left_value, right_value) = (0, 0)
for i in range(len(left)):
	if left[i].isdigit():
		left_value += int(left[i]) * (len(left) - i)
for i in range(len(right)):
	if right[i].isdigit():
		right_value += int(right[i]) * (i + 1)
if left_value < right_value:
	print('right')
elif left_value == right_value:
	print('balance')
else:
	print('left')


import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__
lever = input()
leverIdx = lever.find('^')
leftForce = 0
rightForce = 0
for i in range(len(lever)):
	if lever[i] != '=' and lever[i] != '^':
		mass = int(lever[i])
		dist = abs(leverIdx - i)
		force = mass * dist
		if i < leverIdx:
			leftForce += force
		else:
			rightForce += force
if leftForce == rightForce:
	print('balance')
elif leftForce > rightForce:
	print('left')
else:
	print('right')


s = input()
c = 0
m = s.index('^')
for d in range(len(s)):
	if s[d].isnumeric():
		c += int(s[d]) * (d - m)
if c == 0:
	print('balance')
elif c < 0:
	print('left')
elif c > 0:
	print('right')


import sys

def readInputs():
	global tab, iPiv
	ch = f.readline()[:-1]
	tab = len(ch) * [0]
	for i in range(len(ch)):
		if ch[i] == '^':
			iPiv = i
		elif ch[i] != '=':
			tab[i] = int(ch[i])

def solve():
	sumCoeff = 0
	sumPond = 0
	for i in range(len(tab)):
		sumPond += tab[i] * i
		sumCoeff += tab[i]
	if sumCoeff == 0:
		return 'balance'
	iBary = sumPond / sumCoeff
	if iBary < iPiv:
		return 'left'
	elif iBary > iPiv:
		return 'right'
	else:
		return 'balance'

def tests():
	global f
	bFail = False
	for i in range(1, 3):
		f = open('test' + str(i) + '.txt')
		readInputs()
		lEx = list(map(int, f.readline().split()))
		lEx.sort()
		resExpect = str(lEx)
		res = str(solve())
		if res != resExpect:
			print('TEST', i, 'FAILED !' + ' Found :', res, ', Expected :', resExpect)
			bFail = True
		else:
			print('TEST', i, 'PASSED')
	if not bFail:
		print('\n--- ALL OF THE ' + str(i) + ' TESTS HAVE SUCCEEDED ---')

def main():
	global f
	i = 2
	if i == 1:
		tests()
		return
	f = sys.stdin
	readInputs()
	print(solve())
main()


s = input()
for i in range(len(s)):
	if s[i] == '^':
		o = i
l = s[0:o]
r = s[o + 1:len(s)]
l_sum = r_sum = 0
for i in range(len(l)):
	if not l[i] == '=':
		l_sum += int(l[i]) * (len(l) - i)
for i in range(len(r)):
	if not r[i] == '=':
		r_sum += int(r[i]) * (i + 1)
if l_sum < r_sum:
	print('right')
elif l_sum > r_sum:
	print('left')
else:
	print('balance')


s = input()
distance = 0
for i in range(len(s)):
	if s[i] == '^':
		lever_pos = i
pos = lever_pos - 1
left_mom = 0
while pos >= 0:
	if s[pos] not in ('^', '='):
		left_mom += int(s[pos]) * (lever_pos - pos)
	pos -= 1
pos = lever_pos + 1
right_mom = 0
while pos < len(s):
	if s[pos] not in ('^', '='):
		right_mom += int(s[pos]) * (pos - lever_pos)
	pos += 1
if left_mom > right_mom:
	print('left')
elif right_mom > left_mom:
	print('right')
else:
	print('balance')


lever = input()
Right = True
(massR, massL) = ([], [])
fulcrum = 0
for (i, j) in enumerate(lever):
	if j != '=':
		if j == '^':
			fulcrum = i
			Right = False
		elif Right:
			massR.append((int(j), i))
		else:
			massL.append((int(j), i))
(sumR, sumL) = (0, 0)
for m in massR:
	sumR += abs(fulcrum - m[1]) * m[0]
for m in massL:
	sumL += abs(fulcrum - m[1]) * m[0]
if sumL > sumR:
	print('right')
elif sumR > sumL:
	print('left')
else:
	print('balance')


import sys
inf = float('inf')
(mod, MOD) = (1000000007, 998244353)

def get_array():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def input():
	return sys.stdin.readline().strip()
(left, right) = map(str, input().split('^'))
left = left[::-1]
l = r = 0
for (num, i) in enumerate(left):
	if i != '=':
		l += int(i) * (num + 1)
for (num, i) in enumerate(right):
	if i != '=':
		r += int(i) * (num + 1)
if l == r:
	print('balance')
elif l > r:
	print('left')
else:
	print('right')


s = input()
mid = s.find('^')
sm1 = 0
sm2 = 0
for i in range(mid):
	if s[i] != '=':
		sm1 += int(s[i]) * (mid - i)
for i in range(mid + 1, len(s)):
	if s[i] != '=':
		sm2 += int(s[i]) * (i - mid)
if sm1 - sm2 > 0:
	print('left')
elif sm1 - sm2 < 0:
	print('right')
else:
	print('balance')


l = list(input())
a = l.index('^')
(q, r) = (0, 0)
for x in range(len(l)):
	if x < a and l[x] != '=':
		q += int(l[x]) * (a - x)
	elif x > a and l[x] != '=':
		r += int(l[x]) * (x - a)
if q < r:
	print('right')
elif q > r:
	print('left')
else:
	print('balance')


s = input()
x = s.index('^')
ans = 0
for i in range(len(s)):
	if s[i] == '=' or s[i] == '^':
		continue
	if i < x:
		ans += int(s[i]) * (x - i)
	else:
		ans -= int(s[i]) * (i - x)
if ans == 0:
	print('balance')
elif ans > 0:
	print('left')
else:
	print('right')


lever = input().split('^')
leftWeight = 0
for d in range(len(lever[0])):
	if lever[0][d] != '=':
		leftWeight += int(lever[0][d]) * (len(lever[0]) - d)
rightWeight = 0
for d in range(len(lever[1])):
	if lever[1][d] != '=':
		rightWeight += int(lever[1][d]) * (d + 1)
if leftWeight > rightWeight:
	print('left')
if rightWeight > leftWeight:
	print('right')
if rightWeight == leftWeight:
	print('balance')


from sys import stdin
max_val = int(10000000000000.0)
min_val = int(-10000000000000.0)

def read_int():
	return int(stdin.readline())

def read_ints():
	return [int(x) for x in stdin.readline().split()]

def read_str():
	return input()

def read_strs():
	return [x for x in stdin.readline().split()]
s = input()
n = s.find('^')
m = sum(((i - n) * int(c) for (i, c) in enumerate(s) if c.isdigit()))
print('left' if m < 0 else 'right' if m > 0 else 'balance')


rode = input()
leftLoad = 0
rightLoad = 0
pivotPosition = rode.find('^')
pivot = False
for i in range(len(rode)):
	if rode[i] == '^':
		pivot = True
	elif rode[i].isdigit():
		if pivot:
			rightLoad += abs(pivotPosition - i) * int(rode[i])
		else:
			leftLoad += abs(pivotPosition - i) * int(rode[i])
if leftLoad > rightLoad:
	print('left')
elif rightLoad > leftLoad:
	print('right')
else:
	print('balance')


import sys
import math
from sys import stdin, stdout

def sieve(N):
	primeNumbers = [True] * (N + 1)
	primeNumbers[0] = False
	primeNumbers[1] = False
	i = 2
	while i * i <= N:
		j = i
		if primeNumbers[j]:
			while j * i <= N:
				primeNumbers[j * i] = False
				j += 1
		i += 1
	return primeNumbers

def getPrime(N):
	primes = sieve(N)
	result = []
	for i in range(len(primes)):
		if primes[i]:
			result.append(i)
	return result

def factor(N):
	factors = []
	i = 1
	while i * i <= N:
		if N % i == 0:
			factors.append(i)
			if i != N // i:
				factors.append(N // i)
		i += 1
	return sorted(factors)

def reduceB(b):
	mod = 0
	for i in range(0, len(b)):
		mod = (mod * 10 + ord(b[i])) % 1000000007
	return mod

def gcd(a, b):
	if a < b:
		return gcd(b, a)
	if b == 0:
		return a
	return gcd(b, a % b)

def get_ints_in_variables():
	return map(int, sys.stdin.readline().strip().split())

def get_int():
	return int(input())

def get_ints_in_list():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_list_of_list(n):
	return [list(map(int, sys.stdin.readline().strip().split())) for _ in range(n)]

def get_string():
	return sys.stdin.readline().strip()

def main():
	s = input()
	r = s.index('^')
	sum = 0
	for i in range(len(s)):
		if s[i] != '=' and s[i] != '^':
			sum += int(s[i]) * (i - r)
	if sum < 0:
		print('left')
	elif sum > 0:
		print('right')
	else:
		print('balance')
main()


(left, right) = input().split('^')
l = r = 0
for (i, e) in enumerate(left[::-1]):
	if e != '=':
		l += int(e) * (i + 1)
for (i, e) in enumerate(right):
	if e != '=':
		r += int(e) * (i + 1)
if l == r:
	print('balance')
elif l > r:
	print('left')
else:
	print('right')


def get_sum(side):
	result = 0
	for i in range(len(side)):
		result += side[i][0] * side[i][1]
	return result

def main():
	left = []
	right = []
	s = input()
	middle_pos = s.index('^')
	for i in range(len(s)):
		if s[i] == '=' or s[i] == '^':
			continue
		if i < middle_pos:
			left.append((int(s[i]), abs(middle_pos - i)))
		else:
			right.append((int(s[i]), abs(middle_pos - i)))
	left_sum = get_sum(left)
	right_sum = get_sum(right)
	if left_sum > right_sum:
		print('left')
	elif right_sum > left_sum:
		print('right')
	else:
		print('balance')

def __starting_point():
	main()
__starting_point()


bot = True
l = input()
p = l.index('^')
b = sum(((i - p) * int(x) for (i, x) in enumerate(l) if x.isdigit()))
if b != 0:
	b //= abs(b)
print(['left', 'balance', 'right'][b + 1])


def f(s):
	i = s.index('^')
	s = [0 if c == '^' or c == '=' else int(c) for c in s]
	l = s[:i + 1]
	r = s[i:]
	l.reverse()
	lw = sum([i * l[i] for i in range(len(l))])
	rw = sum([i * r[i] for i in range(len(r))])
	if lw == rw:
		return 'balance'
	return 'left' if lw > rw else 'right'
s = list(input())
print(f(s))


s = list(input())
ind = s.index('^')
left = 0
right = 0
rig = False
for (i, char) in enumerate(s):
	if char == '^':
		rig = True
	if char.isdigit() and (not rig):
		left += int(char) * (ind - i)
	elif char.isdigit() and rig:
		right += int(char) * (i - ind)
if left == right:
	print('balance')
elif left < right:
	print('right')
else:
	print('left')


s = [n for n in input()]
k = s.index('^')
a = s[:k][::-1]
b = s[k + 1:]
m = 0
for n in range(len(a)):
	if ord('0') <= ord(a[n]) <= ord('9'):
		m += int(a[n]) * (n + 1)
p = 0
for n in range(len(b)):
	if ord('0') <= ord(b[n]) <= ord('9'):
		p += int(b[n]) * (n + 1)
if m == p:
	print('balance')
elif m > p:
	print('left')
elif m < p:
	print('right')


n = input()
p = n.index('^')
l = 0
r = 0
for i in range(len(n)):
	if n[i] != '=' and i != p:
		k = n[i]
		if i < p:
			l += (p - i) * int(k)
		elif i > p:
			r += (i - p) * int(k)
if l == r:
	print('balance')
elif l > r:
	print('left')
else:
	print('right')


s = input()
z = s.find('^')
a = s[:z]
b = s[z + 1:]
x = '123456789'
s1 = 0
s2 = 0
if set(a) == set(b) and set(a) == {'='}:
	print('balance')
else:
	for i in range(len(a)):
		if a[i] in x:
			s1 += int(a[i]) * (len(a) - i)
	for j in range(len(b)):
		if b[j] in x:
			s2 += int(b[j]) * (j + 1)
	if s1 == s2:
		print('balance')
	elif s1 > s2:
		print('left')
	else:
		print('right')


def calc_weight(s):
	w = 0
	for (i, v) in enumerate(s):
		if v != '=':
			w += (i + 1) * int(v)
	return w
(l, r) = input().split('^')
(a, b) = (calc_weight(l[::-1]), calc_weight(r))
if a == b:
	print('balance')
elif a < b:
	print('right')
else:
	print('left')


import sys
import math
instr = sys.stdin.readline().split('^')
ll = len(instr[0])
lr = len(instr[1]) - 1
res1 = 0
for i in range(ll - 1, -1, -1):
	if instr[0][i] != '=':
		res1 += int(instr[0][i]) * (i - ll)
res2 = 0
for i in range(lr):
	if instr[1][i] != '=':
		res2 += int(instr[1][i]) * (i + 1)
res = res1 + res2
if res > 0:
	print('right')
elif res < 0:
	print('left')
elif res == 0:
	print('balance')


s = input().split('^')
first = list(s[0]).copy()
first.reverse()
second = list(s[1]).copy()
left = 0
right = 0
for x in range(1, len(first) + 1):
	if first[x - 1] != '=':
		left += x * int(first[x - 1])
for x in range(1, len(second) + 1):
	if second[x - 1] != '=':
		right += x * int(second[x - 1])
if left > right:
	print('left')
elif left == right:
	print('balance')
else:
	print('right')


s = input()
p = s.find('^')
x = list(range(-p, len(s) - p))
w = sum((0 if s[i] is '=' or s[i] is '^' else int(s[i]) * x[i] for i in range(len(s))))
if w < 0:
	print('left')
elif w is 0:
	print('balance')
else:
	print('right')


s = input()
pivot_pos = 0
left_count = 0
right_count = 0
for i in range(len(s)):
	if s[i] == '^':
		pivot_pos = i
for i in range(pivot_pos):
	if s[i].isdigit() == True:
		left_count = left_count + int(s[i]) * (pivot_pos - i)
for i in range(pivot_pos, len(s)):
	if s[i].isdigit() == True:
		right_count = right_count + int(s[i]) * (i - pivot_pos)
if left_count == right_count:
	print('balance')
elif left_count > right_count:
	print('left')
else:
	print('right')


s = str(input())
leftroq = 0
change = 0
righttroq = 0
pivot = s.index('^')
for j in range(len(s)):
	if s[j].isalnum() and change == 0:
		leftroq += int(s[j]) * (pivot - j)
	elif j == pivot:
		change += 1
	elif s[j].isalnum() and change == 1:
		righttroq += int(s[j]) * (j - pivot)
if leftroq > righttroq:
	print('left')
elif righttroq > leftroq:
	print('right')
else:
	print('balance')


a = list(input())
x = a.index('^')
l = 0
r = 0
for (i, j) in enumerate(a):
	if i < x and j != '=':
		l += int(j) * (x - i)
	if i > x and j != '=':
		r += int(j) * (i - x)
if l > r:
	print('left')
elif r > l:
	print('right')
else:
	print('balance')


s = input()
for i in range(len(s)):
	if s[i] == '^':
		xl = i
		xr = i
		left = 0
		right = 0
		while xl != 0:
			xl -= 1
			if s[xl] == '=':
				continue
			if int(s[xl]) in range(1, 10):
				left += int(s[xl]) * abs(xl - i)
		while xr != len(s) - 1:
			xr += 1
			if s[xr] == '=':
				continue
			if int(s[xr]) in range(1, 10):
				right += int(s[xr]) * abs(xr - i)
		if left == right:
			print('balance')
		elif max(left, right) == left:
			print('left')
		else:
			print('right')


s = str(input())
pivot = int(0)
for x in s:
	if x == '^':
		break
	else:
		pivot += 1
left = int(0)
right = int(0)
l = 1
for i in range(pivot - 1, -1, -1):
	if s[i] == '=':
		l += 1
		continue
	else:
		left += int(s[i]) * l
		l += 1
l = 1
for i in range(pivot + 1, int(len(s))):
	if s[i] == '=':
		l += 1
		continue
	else:
		right += int(s[i]) * l
		l += 1
if right == left:
	print('balance')
elif right > left:
	print('right')
else:
	print('left')


s = input()
l = len(s)
i = s.index('^')
lh = s[:i]
rh = s[i + 1:]
ls = rs = 0
for x in range(len(lh)):
	if lh[x] != '=':
		ls += int(lh[x]) * (len(lh) - x)
for x in range(len(rh)):
	if rh[x] != '=':
		rs += int(rh[x]) * (x + 1)
if ls == rs:
	print('balance')
elif ls < rs:
	print('right')
else:
	print('left')


s = input()
n = s.find('^')
m = sum(((i - n) * int(c) for (i, c) in enumerate(s) if c.isdigit()))
print('left' if m < 0 else 'right' if m > 0 else 'balance')


k = input().split('^')
l = sum([(ord(x) - ord('0')) * (len(k[0]) - i + 1) for (i, x) in enumerate(k[0], 1) if x != '='])
r = sum([(ord(x) - ord('0')) * i for (i, x) in enumerate(k[1], 1) if x != '='])
print('balance' if l == r else 'left' if l > r else 'right')


s = list(input())
mid = 0
su = 0
for i in range(len(s)):
	if s[i] == '^':
		mid = i
		break
for i in range(len(s)):
	if s[i] != '^' and s[i] != '=':
		su += int(s[i]) * (i - mid)
if su == 0:
	print('balance')
elif su < 0:
	print('left')
else:
	print('right')


def solve(s):
	(sl, sr) = s.split('^')
	left = sum([(i + 1) * int(c) for (i, c) in enumerate(reversed(sl)) if c.isdigit()])
	right = sum([(i + 1) * int(c) for (i, c) in enumerate(sr) if c.isdigit()])
	if left > right:
		return 'left'
	elif left == right:
		return 'balance'
	else:
		return 'right'
s = input()
print(solve(s))


from sys import stdin

def read_lines(sep=' ', input_type=None):
	_lines = stdin.readlines()
	cast = input_type is not None
	lines = []
	for line in _lines:
		line = line[:-1].split(sep)
		if cast:
			line = [input_type(x) for x in line]
		lines.append(line)
	return lines
lines = read_lines(input_type=None)
string = lines[0][0]
LEVER_SENTINEL = '^'
i_lever = None
for (i, s) in enumerate(string):
	if s == LEVER_SENTINEL:
		i_lever = i
		break
balance = 0
for (i, s) in enumerate(string):
	if s.isnumeric():
		balance += (i_lever - i) * int(s)
if balance < 0:
	print('right')
elif balance > 0:
	print('left')
else:
	print('balance')


def main():
	s = input()
	res = 0
	for (i, c) in enumerate(s, -s.find('^')):
		if c.isdigit():
			res += i * int(c)
	print(('left', 'right', 'balance')[(not res) * 2 + (res > 0)])
main()


from collections import deque as de
import math
import sys
import re
from collections import Counter as cnt
from functools import reduce
from typing import MutableMapping
from itertools import groupby as gb
from fractions import Fraction as fr
from bisect import bisect_left as bl, bisect_right as br

def factors(n):
	return set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))

class My_stack:

	def __init__(self):
		self.data = []

	def my_push(self, x):
		return self.data.append(x)

	def my_pop(self):
		return self.data.pop()

	def my_peak(self):
		return self.data[-1]

	def my_contains(self, x):
		return self.data.count(x)

	def my_show_all(self):
		return self.data

	def isEmpty(self):
		return len(self.data) == 0
arrStack = My_stack()

def decimalToBinary(n):
	return bin(n).replace('0b', '')

def binarytodecimal(n):
	return int(n, 2)

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

def get_prime_factors(number):
	prime_factors = []
	while number % 2 == 0:
		prime_factors.append(2)
		number = number / 2
	for i in range(3, int(math.sqrt(number)) + 1, 2):
		while number % i == 0:
			prime_factors.append(int(i))
			number = number / i
	if number > 2:
		prime_factors.append(int(number))
	return prime_factors

def get_frequency(list):
	dic = {}
	for ele in list:
		if ele in dic:
			dic[ele] += 1
		else:
			dic[ele] = 1
	return dic

def Log2(x):
	return math.log10(x) / math.log10(2)

def getProduct(n):
	product = 1
	while n != 0:
		product = product * (n % 10)
		n = n // 10
	return product

def dupconscount(nums):
	element = []
	freque = []
	if not nums:
		return element
	running_count = 1
	for i in range(len(nums) - 1):
		if nums[i] == nums[i + 1]:
			running_count += 1
		else:
			freque.append(running_count)
			element.append(nums[i])
			running_count = 1
	freque.append(running_count)
	element.append(nums[i + 1])
	return (element, freque)

def lcm(x, y):
	lcm = x * y // math.gcd(x, y)
	return lcm

def isPowerOfTwo(n):
	return math.ceil(Log2(n)) == math.floor(Log2(n))

def checkisap(list):
	d = list[1] - list[0]
	for i in range(2, len(list)):
		temp = list[i] - list[i - 1]
		if temp != d:
			return False
	return True

def ceildiv(x, y):
	return (x + y - 1) // y

def di():
	return map(int, input().split())

def ii():
	return int(input())

def li():
	return list(map(int, input().split()))

def si():
	return list(map(str, input()))

def indic():
	dic = {}
	for (index, value) in enumerate(input().split()):
		dic[int(value)] = int(index) + 1
	return dic
lever = list(map(str, input().split('^')))
left = lever[0][::-1]
right = lever[1]
ls = 0
rs = 0
for i in range(len(left)):
	if left[i].isdigit():
		ls += int(left[i]) * (i + 1)
for i in range(len(right)):
	if right[i].isdigit():
		rs += int(right[i]) * (i + 1)
if ls == rs:
	print('balance')
elif ls > rs:
	print('left')
else:
	print('right')


s = input().split('^')
(left, right) = (0, 0)
for i in range(len(s[0])):
	if s[0][i] != '=':
		left += int(s[0][i]) * (len(s[0]) - i)
for i in range(len(s[1])):
	if s[1][i] != '=':
		right += int(s[1][i]) * (i + 1)
print([['left', 'right'][right > left], 'balance'][left == right])


perekladina = input()
opora = perekladina.find('^')
answer = 0
for i in range(opora):
	if perekladina[i] != '=':
		answer += int(perekladina[i]) * (opora - i)
for i in range(opora + 1, len(perekladina)):
	if perekladina[i] != '=':
		answer -= int(perekladina[i]) * (i - opora)
print('balance' if not answer else 'left' if answer > 0 else 'right')


n = input()
zn = 0
wyn = 0
for i in range(len(n)):
	if n[i] == '^':
		zn = i
for i in range(len(n)):
	if n[i] != '^' and n[i] != '=':
		wyn += (zn - i) * int(n[i])
if wyn == 0:
	print('balance')
elif wyn > 0:
	print('left')
else:
	print('right')


s = input()
(lw, cw) = (0, 0)
sum = 0
mid = s.index('^')
for i in range(len(s)):
	if s[i] != '=' and s[i] != '^':
		sum += int(s[i]) * (i - mid)
if sum < 0:
	print('left')
elif sum > 0:
	print('right')
else:
	print('balance')


s = input()
left = ''.join(reversed(s[0:s.index('^')]))
right = s[s.index('^') + 1:]
(sum1, sum2) = (0, 0)
for i in range(len(left)):
	if left[i] in '123456789':
		sum1 += int(left[i]) * (i + 1)
for i in range(len(right)):
	if right[i] in '123456789':
		sum2 += int(right[i]) * (i + 1)
print('right' if sum2 > sum1 else 'left' if sum2 < sum1 else 'balance')


s = input()
n = len(s)
for i in range(n):
	if s[i] == '^':
		x = i
		break
a = b = 0
for i in range(x):
	if s[i] >= '1' and s[i] <= '9':
		a += (int(s[i]) - int('0')) * (x - i)
for i in range(x, n):
	if s[i] >= '1' and s[i] <= '9':
		b += (int(s[i]) - int('0')) * (i - x)
if a == b:
	print('balance')
else:
	print('left' if a > b else 'right')


left = 0
right = 0
n = input()
l = len(n)
fulcrum = n.find('^')
left_half = n[0:fulcrum]
right_half = n[fulcrum + 1:l]
left_half = left_half[::-1]
for i in range(len(left_half)):
	if left_half[i].isalnum():
		left = left + int(left_half[i]) * (i + 1)
for j in range(len(right_half)):
	if right_half[j].isalnum():
		right = right + int(right_half[j]) * (j + 1)
if left == right:
	print('balance')
elif left < right:
	print('right')
else:
	print('left')


string = input()
pivot = string.index('^')
sm = 0
for index in range(0, len(string)):
	if string[index:index + 1] != '^' and string[index:index + 1] != '=':
		sm += (pivot - index) * int(string[index:index + 1])
if sm < 0:
	print('right')
elif sm > 0:
	print('left')
else:
	print('balance')


q = input().split('^')
(lw, rw, l2) = (0, 0, len(q[0]))
for i in range(l2):
	if q[0][i].isdigit():
		lw += int(q[0][i]) * (l2 - i)
for i in range(len(q[1])):
	if q[1][i].isdigit():
		rw += int(q[1][i]) * (i + 1)
if lw == rw:
	print('balance')
elif lw > rw:
	print('left')
else:
	print('right')


S = input()
p = S.index('^')
l = 0
r = 0
for i in range(p - 1, -1, -1):
	if S[i] != '=':
		l += int(S[i]) * (p - i)
for i in range(p + 1, len(S)):
	if S[i] != '=':
		r += int(S[i]) * (i - p)
if l > r:
	print('left')
elif r > l:
	print('right')
else:
	print('balance')


s = list(input())
level = s.index('^')
left = 0
for i in range(level):
	try:
		left += int(s[i]) * (level - i)
	except ValueError:
		continue
right = 0
for i in range(level + 1, len(s)):
	try:
		right += int(s[i]) * (i - level)
	except ValueError:
		continue
if left == right:
	print('balance')
elif left > right:
	print('left')
else:
	print('right')


from sys import stdout, stdin, setrecursionlimit
from io import BytesIO, IOBase
from collections import *
from itertools import *
from random import *
from bisect import *
from string import *
from queue import *
from heapq import *
from math import *
from re import *
from os import *

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = read(self._fd, max(fstat(self._fd).st_size, 8192))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = read(self._fd, max(fstat(self._fd).st_size, 8192))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(stdin, stdout) = (IOWrapper(stdin), IOWrapper(stdout))
(graph, mod, szzz) = ({}, 10 ** 9 + 7, lambda : sorted(zzz()))

def getInt():
	return int(input())

def listStr():
	return list(input())

def getStrs():
	return input().split()

def isInt(s):
	return '0' <= s[0] <= '9'

def input():
	return stdin.readline().strip()

def zzz():
	return [int(i) for i in input().split()]

def output(answer, end='\n'):
	stdout.write(str(answer) + end)

def lcd(xnum1, xnum2):
	return xnum1 * xnum2 // gcd(xnum1, xnum2)
dx = [-1, 1, 0, 0, 1, -1, 1, -1]
dy = [0, 0, 1, -1, 1, -1, -1, 1]
daysInMounth = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
s = input()
r = s.index('^')
res = 0
for i in range(len(s)):
	if s[i] != '=' and s[i] != '^':
		res += int(s[i]) * (i - r)
if res < 0:
	print('left')
elif res > 0:
	print('right')
else:
	print('balance')


s = [d for d in input()]
w = [0, 0]
p = s.index('^')
d = 0
for i in range(len(s)):
	if s[i] == '^':
		d = 1
	elif s[i] == '=':
		continue
	else:
		w[d] += int(s[i]) * abs(p - i)
if w[0] == w[1]:
	print('balance')
elif w[0] > w[1]:
	print('left')
else:
	print('right')


s = str(input())
l = 0
r = 0
s = s.replace(' ', '')
sl = ''
sr = ''
b = True
for i in range(len(s)):
	if s[i] == '^':
		b = False
		continue
	if b:
		sl += s[i]
	else:
		sr += s[i]
sl = sl[::-1]
for i in range(len(sl)):
	if sl[i] != '=':
		l += (i + 1) * int(sl[i])
for i in range(len(sr)):
	if sr[i] != '=':
		r += (i + 1) * int(sr[i])
if l > r:
	print('left')
if r == l:
	print('balance')
if l < r:
	print('right')


x = input()
p = x.find('^')
le = 0
ri = 0
for i in range(len(x)):
	if x[i] != '=' and x[i] != '^':
		if p - i > 0:
			le += (p - i) * int(x[i])
		elif p - i < 0:
			ri += abs(p - i) * int(x[i])
if le < ri:
	print('right')
elif le > ri:
	print('left')
elif le == ri:
	print('balance')


s = input()
a = s.find('^')
length = len(s)
s = list(s)
sum_left = 0
i = -1
sum_right = 0
for x in s:
	i += 1
	if x != '=' and x != '^' and (i < a):
		x = int(x)
		sum_left += x * (a - i)
	elif x != '=' and x != '^' and (i > a):
		x = int(x)
		sum_right += x * (i - a)
if sum_right > sum_left:
	print('right')
elif sum_right < sum_left:
	print('left')
else:
	print('balance')


a = input()
d = ''
for i in a:
	if i == '=':
		d += '0'
	else:
		d += i
d = d.split('^')
b = 0
c = 0
for i in range(1, len(d[0]) + 1):
	b += i * int(d[0][-i])
for i in range(len(d[1])):
	c += (i + 1) * int(d[1][i])
if b == c:
	print('balance')
elif b > c:
	print('left')
else:
	print('right')


s = input()
piv = s.index('^')
l = 0
r = 0
k = 1
for i in range(piv - 1, -1, -1):
	if s[i] != '=':
		w = int(s[i])
		l += k * w
	k += 1
k = 1
for i in range(piv + 1, len(s)):
	if s[i] != '=':
		w = int(s[i])
		r += k * w
	k += 1
if l == r:
	print('balance')
elif l < r:
	print('right')
else:
	print('left')


s = input()
s = list(s)
t1 = s.index('^')
(t2, t3) = (0, 0)
for i in range(len(s)):
	if i < t1 and s[i] != '=':
		s[i] = int(s[i]) * abs(t1 - i)
		t2 += s[i]
	elif i > t1 and s[i] != '=':
		s[i] = int(s[i]) * abs(t1 - i)
		t3 += s[i]
if t2 < t3:
	print('right')
elif t2 > t3:
	print('left')
else:
	print('balance')


from sys import stdin
x = stdin.readline().rstrip()
s = [i for i in x]
mid = s.index('^')
sm = 0
for i in range(len(s)):
	if s[i] != '=' and s[i] != '^':
		sm += int(s[i]) * (i - mid)
if sm < 0:
	print('left')
elif sm > 0:
	print('right')
else:
	print('balance')


l1 = list(input())
x = l1.index('^')
flag = 0
balance = 0
for i in range(len(l1)):
	if i == x:
		continue
	if l1[i] != '=':
		if i < x:
			balance += int(l1[i]) * (x - i)
		else:
			balance -= int(l1[i]) * (i - x)
if balance > 0:
	print('left')
elif balance == 0:
	print('balance')
else:
	print('right')