using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace codeforces
{
	class Program
	{
		public const int Osn = 1000000007;

		public class Pair
		{
			public long First;

			public long Second;
		}

		public class PairComparer : IComparer<Pair>
		{
			public int Compare(Pair x, Pair y)
			{
				if (x.First < y.First || (x.First == y.First && x.Second < y.Second))
					return -1;
				return 1;
			}
		}

		public static long GetGcd(long a, long b)
		{
			while (true)
			{
				if (b == 0)
					return a;
				var a1 = a;
				a = b;
				b = a1 % b;
			}
		}

		public static void WriteYesNo(bool x, string yes = "YES", string no = "NO")
		{
			if (x)
				Console.WriteLine(yes);
			else
			{
				Console.WriteLine(no);
			}
		}

		public static string ReadString()
		{
			return Console.ReadLine();
		}

		public static List<int> ReadListOfInts()
		{
			var s = Console.ReadLine();
			return s.Split(' ').Select(int.Parse).ToList();
		}

		public static List<long> ReadListOfLongs()
		{
			var s = Console.ReadLine();
			return s.Split(' ').Select(long.Parse).ToList();
		}

		public static int ReadInt()
		{
			var s = Console.ReadLine();
			return int.Parse(s);
		}

		public static long ReadLong()
		{
			var s = Console.ReadLine();
			return long.Parse(s);
		}

		public class Vertex
		{
			public int Was;

			public List<Pair> Edges;
		}

		public static List<List<Vertex>> Graph = new List<List<Vertex>>();

/*		public static bool Dfs(int x, int y, int prevx, int prevy)
		{
			Graph[x][y].Was = 1;
			var result = false;
			foreach (var t in Graph[x][y].Edges)
			{
				if (Graph[t.First][t.Second].Was == 0)
					result |= Dfs(t.First, t.Second, x, y);
				else if (t.First != prevx || t.Second != prevy)
					return true;
			}

			return result;
		}*/

		public static bool IsPrime(int x)
		{
			for (var j = 2; j * j <= x; ++j)
				if (x % j == 0)
					return false;
			return true;
		}

		private static void Main()
		{
			var s = ReadString().Split('^');
			long sum1 = 0;
			long sum2 = 0;
			for (var i = 0; i < s[0].Length; ++i)
				if (s[0][i] != '=')
				{
					sum1 += ((s[0].Length - i) * (s[0][i] - '0'));
				}
			for (var i = 0; i < s[1].Length; ++i)
				if (s[1][i] != '=')
				{
					sum2 += ((i + 1) * (s[1][i] - '0'));
				}
			if (sum1 > sum2)
				Console.WriteLine("left");
			if (sum1 == sum2)
				Console.WriteLine("balance");
			if (sum1 < sum2)
				Console.WriteLine("right");

			Console.ReadLine();
		}
	}
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace lever
{
    class Program
    {
        static void Main(string[] args)
        {
            string str = Console.ReadLine();
            int n = str.Length;
            char[] ch = str.ToCharArray();
            Int64 sum1 = 0, sum2 = 0;
            int i, j;
            Int64 pivot_pos = str.IndexOf('^');

            for (i = 0; i < n && ch[i] != '^'; i++)
                if (ch[i] != '=')
                    sum1 += (Convert.ToInt64(ch[i].ToString())*(pivot_pos-i));

            for (j = i + 1; j < n; j++)
                if (ch[j] != '=')
                    sum2 += (Convert.ToInt64(ch[j].ToString()) * (j - pivot_pos));

            if (sum1 == sum2)
                Console.WriteLine("balance");
            else if (sum1 > sum2)
                Console.WriteLine("left");
            else
                Console.WriteLine("right");

            Console.ReadLine();
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string st=Console.ReadLine();
            string []st2=st.Split('^');
            Int64 f=0;
            for(int i=st2[0].Length-1;i>=0;i--)
            {
                if (st2[0][i] != '=') f += (Int64)(((int)(st2[0][i]) - 48) * (st2[0].Length - i));
            }
            for (int i = 0; i < st2[1].Length ; i++)
            {
                if (st2[1][i] != '=') f -= (Int64)(((int)(st2[1][i]) - 48) * (i+ 1));
            }
            if (f == 0)
            {
                Console.WriteLine("balance");
            }
            else if (f > 0)
            {
                Console.WriteLine("left");
            }
            else if (f < 0)
            {
                Console.WriteLine("right");
            }
        }
    }
}


using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;

namespace MakeCalendar
{
    public static class MainClass
    {

        static int ReadIntLine()
        {
            return int.Parse(Console.ReadLine());
        }

        static void ReadInt(ref int a)
        {
            a = ReadIntArrayLine()[0];
        }

        static void ReadInts(ref int a, ref int b)
        {
            var x = ReadIntArrayLine();
            a = x[0]; b = x[1];
        }

        static void ReadInts(ref int a, ref int b, ref int c)
        {
            var x = ReadIntArrayLine();
            a = x[0]; b = x[1]; c = x[2];
        }

        static void ReadInts(ref int a, ref int b, ref int c, ref int d)
        {
            var x = ReadIntArrayLine();
            a = x[0]; b = x[1]; c = x[2]; d = x[3];
        }

        static int[] ReadIntArrayLine()
        {
            char[] sep = { ' ' };
            return Console.ReadLine().Split(sep, StringSplitOptions.RemoveEmptyEntries).Select(x => int.Parse(x)).ToArray();
        }

        static void PrintLn(object obj)
        {
            Console.WriteLine(obj.ToString());
        }

        public static string Reverse(string s)
        {
            char[] charArray = s.ToCharArray();
            Array.Reverse(charArray);
            return new string(charArray);
        }

        public static void PrintLnCollection<T>(IEnumerable<T> col)
        {
            PrintLn(string.Join(" ",col));
        }

        public static string ReadLine()
        {
            return Console.ReadLine();
        }

        public static string MySubstring(this string str, int start, int finish)
        {
            return str.Substring(start, finish - start + 1);
        }

        public static bool IsInRange(this int a, int lb, int ub)
        {
            return (a>=lb) && (a<=ub);
        }

//----------------------------------------------------------------------------

        static void Main(string[] args)
        {
            string s = ReadLine();

            int pivot = s.IndexOf('^');

            decimal t = 0;

            for (int i = 0; i < s.Length; i++)
            {
                if (char.IsDigit(s[i]))
                    t += (s[i] - 48) * (i - pivot);
            }

            if (t < 0)
                PrintLn("left");
            else if (t > 0)
                PrintLn("right");
            else
                PrintLn("balance");

        }

    }
}


fun main() {
    val bar = readLine()!!
    val middle = bar.indexOf('^')
    var left = 0L
    for (pos in 0 until middle) if (bar[pos] != '=') left += (middle - pos) * (bar[pos] - '0')
    var right = 0L
    for (pos in middle + 1 until bar.length) if (bar[pos] != '=') right += (pos - middle) * (bar[pos] - '0')
    print(
        when {
            left == right -> "balance"
            left > right -> "left"
            else -> "right"
        }
    )
}


#include<bits/stdc++.h>
using namespace std;

string s;

int main()
{
	cin >> s;
	int bas = 0;
	for(int i = 0; i < s.size(); ++ i)
		if(s[i] == '^')
			bas = i;
	long long cnt1 = 0, cnt2 = 0;
	for(int i = 0; i < bas; ++ i)
		if(s[i] != '=')
			cnt1 = cnt1 + (bas - i) * (s[i] - '0');
	for(int i = bas; i < s.size(); ++ i)
		if(s[i] != '=' && s[i] != '^')
			cnt2 = cnt2 + (i - bas) * (s[i] - '0');
	if(cnt1 > cnt2)
	{
		cout << "left" << endl;
		return 0;
	}
	if(cnt2 > cnt1)
	{
		cout << "right" << endl;
		return 0;
	}
	cout << "balance" << endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;

string s;

int main()
{
	cin >> s;
	int bas = 0;
	for(int i = 0; i < s.size(); ++ i)
		if(s[i] == '^')
			bas = i;
	int cnt1 = 0, cnt2 = 0;
	for(int i = 0; i < bas; ++ i)
		if(s[i] != '=')
			cnt1 = cnt1 + (bas - i) * (s[i] - '0');
	for(int i = bas; i < s.size(); ++ i)
		if(s[i] != '=' && s[i] != '^')
			cnt2 = cnt2 + (i - bas) * (s[i] - '0');
	if(cnt1 < cnt2)
	{
		cout << "left" << endl;
		return 0;
	}
	if(cnt2 > cnt1)
	{
		cout << "right" << endl;
		return 0;
	}
	cout << "balance" << endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;

string s;

int main()
{
	cin >> s;
	int bas = 0;
	for(int i = 0; i < s.size(); ++ i)
		if(s[i] == '^')
			bas = i;
	int cnt1 = 0, cnt2 = 0;
	for(int i = 0; i < bas; ++ i)
		if(s[i] != '=')
			cnt1 = cnt1 + (bas - i) * (s[i] - '0');
	for(int i = bas; i < s.size(); ++ i)
		if(s[i] != '=' && s[i] != '^')
			cnt2 = cnt2 + (i - bas) * (s[i] - '0');
	if(cnt1 > cnt2)
	{
		cout << "left" << endl;
		return 0;
	}
	if(cnt2 > cnt1)
	{
		cout << "right" << endl;
		return 0;
	}
	cout << "balance" << endl;
	return 0;
}


#include<iostream>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
#include<queue>
#include<set>
#include<cstdlib>
using namespace std;

const int MAXN = 1000000;
long long a[MAXN+1];
string s;

int main() {
  cin >> s;
  long long l = s.length(), p = 0;
  long long sum = 0;
  for(int i = 0; i < l; i ++) {
    a[i] = 0;
    if(s[i] == '=') continue;
    else if(s[i] == '^') p = i;
    else a[i] = s[i] - '0';
  }
  for(int i = 0; i < l; i ++)
    if(i < p) sum += a[i] * (p - i);
    else sum -= a[i] * (i - p);
  if(sum < 0) cout << "right" << endl;
  else if(sum == 0) cout << "balance" << endl;
  else cout << "left" << endl;
  return 0;
}


#include<iostream>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
#include<queue>
#include<set>
#include<cstdlib>
using namespace std;

const int MAXN = 1000000;
int n, m, k, a[MAXN+1];
string s;

int main() {
  cin >> s;
  int l = s.length(), p = 0, sum = 0;
  for(int i = 0; i < l; i ++) {
    a[i] = 0;
    if(s[i] == '=') continue;
    else if(s[i] == '^') p = i;
    else a[i] = s[i] - '0';
  }
  for(int i = 0; i < l; i ++)
    if(i < p) sum += a[i] * (p - i);
    else sum -= a[i] * (i - p);
  if(sum < 0) cout << "right" << endl;
  else if(sum == 0) cout << "balance" << endl;
  else cout << "left" << endl;
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
struct _ { ios_base::Init i; _() { cin.sync_with_stdio(0); cin.tie(0); } } _;

int main()
{
    string a; cin >> a;
    string x, y;
    int n = a.size();
    for(int i = 0; i < n; ++i)
        if(a[i] == '^')
        {
            x = a.substr(0, i);
            reverse((x).begin(), (x).end());
            y = a.substr(i+1, n-1-i);
            break;
        }

    int sum = 0;
    n = x.size();
    for(int i = 0; i < n; ++i)
        sum += (i+1) * (('0' <= x[i] and x[i] <= '9') ? (x[i]-'0') : 0);

    n = y.size();
    for(int i = 0; i < n; ++i)
        sum -= (i+1) * (('0' <= y[i] and y[i] <= '9') ? (y[i]-'0') : 0);

    puts( (sum > 0) ? "left" : ((sum < 0) ? "right" : "balance"));
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
struct _ { ios_base::Init i; _() { cin.sync_with_stdio(0); cin.tie(0); } } _;

int main()
{
    string a; cin >> a;
    string x, y;
    int n = a.size();
    for(int i = 0; i < n; ++i)
        if(a[i] == '^')
        {
            x = a.substr(0, i);
            reverse((x).begin(), (x).end());
            y = a.substr(i+1, n-1-i);
            break;
        }

    long long sum = 0;
    n = x.size();
    for(int i = 0; i < n; ++i)
        sum += (long long)(i+1) * (('0' <= x[i] and x[i] <= '9') ? (x[i]-'0') : 0);

    n = y.size();
    for(int i = 0; i < n; ++i)
        sum -= (long long)(i+1) * (('0' <= y[i] and y[i] <= '9') ? (y[i]-'0') : 0);

    puts( (sum > 0) ? "left" : ((sum < 0) ? "right" : "balance"));
    return 0;
}


#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main(int argc, char *argv[])
{   string S;
    vector<vector<int> >L(10);
    getline(cin,S);
    int i,N=S.size();
    for(i=0;i<N;i++)
    {if(S[i]=='^')break;
     if(S[i]!='=')L[S[i]-'0'].push_back(i);
    }
    long long R=0,j,k;
    for(j=i+1,k=1;j<N;k++,j++)
    if(S[j]!='=')R+=k*(S[j]-'0');
    for(k=1;k<=9 && R>=0;k++)
      for(j=0;j<L[k].size() && R>=0;j++)
      R-=k*(i-L[k][j]);
    if(!R)cout<<"balance";
    else if(R>0)cout<<"right";
    else cout<<"left";

    return EXIT_SUCCESS;
}


#include <bits/stdc++.h>

using namespace std;

/* Template */

#define ll long long
#define foreach(it, S) for(__typeof (S.begin()) it = S.begin(); it != S.end(); it++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define MN(a, b) a = min (a, b)
#define MX(a, b) a = max (a, b)
#define endl '\n'

#define fname ""

#define nxtnt getNext <int>()
#define nxtll getNext <ll>()

template <typename T> inline T getNext () { T s = 1, x = 0, c = getc(stdin); while (c <= 32) c = getc(stdin); if (c == '-')	s = -1, c = getc(stdin); while ('0' <= c && c <= '9') x = x * 10 + c - '0', c = getc(stdin); return x * s; }

const int MaxN = int (1e5);

int find (string &s, char w) {
	for (int i = 0; i < s.size(); ++i)
		if (s[i] == '^')
			return i;
	return -1;
}

int main () {
	#ifdef lcl
		freopen (fname".in", "r", stdin);
		// freopen (fname".out", "w", stdout);
	#endif

	string s; cin >> s;
	int k = find (s, '^');

	int LeftSide = 0, RightSide = 0;

	for (int i = k; i >= 0; --i) {
		// cout << s[i] << " " << k - i + 1 << endl;
		if (s[i] != '=' && s[i] != '^')
			LeftSide += (k - i + 1) * (s[i] - '0');
			// cout << k - i + 1 << " " << s[i] << endl;
	}
	// cout << "/-------/\n";
	for (int i = k + 1; i < s.size(); ++i) {
		if (s[i] != '=' && s[i] != '^') {
			RightSide += (i - k - 1) * (s[i] - '0');
			// cout << i - k - 1 << " " << s[i] << endl;
		}
	}

	// cout << LeftSide << " " << RightSide << endl;

	if (LeftSide > RightSide)
		cout << "left";
	else
		if (LeftSide < RightSide)
			cout << "right";
		else
			cout << "balance";
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

/* Template */

#define ll long long
#define foreach(it, S) for(__typeof (S.begin()) it = S.begin(); it != S.end(); it++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define MN(a, b) a = min (a, b)
#define MX(a, b) a = max (a, b)
#define endl '\n'

#define fname ""

#define nxtnt getNext <int>()
#define nxtll getNext <ll>()

template <typename T> inline T getNext () { T s = 1, x = 0, c = getc(stdin); while (c <= 32) c = getc(stdin); if (c == '-')	s = -1, c = getc(stdin); while ('0' <= c && c <= '9') x = x * 10 + c - '0', c = getc(stdin); return x * s; }

const int MaxN = int (1e5);

bool find (string &s, char w) {
	for (int i = 0; i < s.size(); ++i)
		if (s[i] == 'w')
			return i;
	return -1;
}

int main () {
	#ifdef lcl
		freopen (fname".in", "r", stdin);
		// freopen (fname".out", "w", stdout);
	#endif

	string s; cin >> s;
	int k = find (s, '^');

	int LeftSide = 0, RightSide = 0;

	for (int i = k; i >= 0; --i) {
		if (s[i] != '=' && s[i] != '^')
			LeftSide += (k - i + 1) * (s[i] - '0');
			// cout << k - i + 1 << " " << s[i] << endl;
	}
	// cout << "/-------/\n";
	for (int i = k + 1; i < s.size(); ++i) {
		if (s[i] != '=' && s[i] != '^') {
			RightSide += (i - k - 1) * (s[i] - '0');
			// cout << i - k - 1 << " " << s[i] << endl;
		}
	}

	// cout << LeftSide << " " << RightSide << endl;

	if (LeftSide > RightSide)
		cout << "left";
	else
		if (LeftSide < RightSide)
			cout << "right";
		else
			cout << "balance";
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

/* Template */

#define ll long long
#define foreach(it, S) for(__typeof (S.begin()) it = S.begin(); it != S.end(); it++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define MN(a, b) a = min (a, b)
#define MX(a, b) a = max (a, b)
#define endl '\n'

#define fname ""

#define nxtnt getNext <int>()
#define nxtll getNext <ll>()

template <typename T> inline T getNext () { T s = 1, x = 0, c = getc(stdin); while (c <= 32) c = getc(stdin); if (c == '-')	s = -1, c = getc(stdin); while ('0' <= c && c <= '9') x = x * 10 + c - '0', c = getc(stdin); return x * s; }

const int MaxN = int (1e5);

int main () {
	#ifdef lcl
		freopen (fname".in", "r", stdin);
		// freopen (fname".out", "w", stdout);
	#endif

	string s; cin >> s;
	int k;

	for (int i = 0; i < s.size(); ++i)
		if (s[i] == '^')
			k = i;

	int L = 0, R = 0;

	for (int i = 0; i < k; ++i)
		L += s[i] == '=' ? 0 : (s[i] - '0') * (k - i);

	for (int i = k + 1; i < s.size(); ++i) {
		R += s[i] == '=' ? 0 : (s[i] - '0') * (i - k);
	}

	if (L > R)
		cout << "left";
	else
		if (L < R)
			cout << "right";
		else
			cout << "balance";
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

/* Template */

#define ll long long
#define foreach(it, S) for(__typeof (S.begin()) it = S.begin(); it != S.end(); it++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define MN(a, b) a = min (a, b)
#define MX(a, b) a = max (a, b)
#define endl '\n'

#define fname ""

#define nxtnt getNext <int>()
#define nxtll getNext <ll>()

template <typename T> inline T getNext () { T s = 1, x = 0, c = getc(stdin); while (c <= 32) c = getc(stdin); if (c == '-')	s = -1, c = getc(stdin); while ('0' <= c && c <= '9') x = x * 10 + c - '0', c = getc(stdin); return x * s; }

const int MaxN = int (1e5);

int find (string &s, char w) {
	for (int i = 0; i < s.size(); ++i)
		if (s[i] == '^')
			return i;
	return -1;
}

int main () {
	#ifdef lcl
		freopen (fname".in", "r", stdin);
		// freopen (fname".out", "w", stdout);
	#endif

	string s; cin >> s;
	int k = find (s, '^');

	int tmp = 0;

	for (int i = 0; i < s.size(); ++i) {
		if (s[i] != '=' && s[i] != '^') {
			tmp += (i - k) * (s[i] - '0');
			// cout << i - k << " " << s[i] << endl;
		}
	}

	// cout << LeftSide << " " << RightSide << endl;

	if (tmp < 0)
		cout << "left";
	else
		if (tmp > 0)
			cout << "right";
		else
			cout << "balance";
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

/* Template */

#define ll long long
#define foreach(it, S) for(__typeof (S.begin()) it = S.begin(); it != S.end(); it++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define MN(a, b) a = min (a, b)
#define MX(a, b) a = max (a, b)
#define endl '\n'

#define fname ""

#define nxtnt getNext <int>()
#define nxtll getNext <ll>()

template <typename T> inline T getNext () { T s = 1, x = 0, c = getc(stdin); while (c <= 32) c = getc(stdin); if (c == '-')	s = -1, c = getc(stdin); while ('0' <= c && c <= '9') x = x * 10 + c - '0', c = getc(stdin); return x * s; }

const int MaxN = int (1e5);

int find (string &s, char w) {
	for (int i = 0; i < s.size(); ++i)
		if (s[i] == '^')
			return i;
	return -1;
}

int main () {
	#ifdef lcl
		freopen (fname".in", "r", stdin);
		// freopen (fname".out", "w", stdout);
	#endif

	string s; cin >> s;
	int k = find (s, '^');

	int LeftSide = 0, RightSide = 0;

	for (int i = k; i >= 0; --i) {
		// cout << s[i] << " " << k - i + 1 << endl;
		if (s[i] != '=' && s[i] != '^')
			LeftSide += (k - i) * (s[i] - '0');
			// cout << k - i << " " << s[i] << endl;
	}
	// cout << "/-------/\n";
	for (int i = k + 1; i < s.size(); ++i) {
		if (s[i] != '=' && s[i] != '^') {
			RightSide += (i - k) * (s[i] - '0');
			// cout << i - k << " " << s[i] << endl;
		}
	}

	// cout << LeftSide << " " << RightSide << endl;

	if (LeftSide > RightSide)
		cout << "left";
	else
		if (LeftSide < RightSide)
			cout << "right";
		else
			cout << "balance";
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

/* Template */

#define ll long long
#define foreach(it, S) for(__typeof (S.begin()) it = S.begin(); it != S.end(); it++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define MN(a, b) a = min (a, b)
#define MX(a, b) a = max (a, b)
#define endl '\n'

#define fname ""

#define nxtnt getNext <int>()
#define nxtll getNext <ll>()

template <typename T> inline T getNext () { T s = 1, x = 0, c = getc(stdin); while (c <= 32) c = getc(stdin); if (c == '-')	s = -1, c = getc(stdin); while ('0' <= c && c <= '9') x = x * 10 + c - '0', c = getc(stdin); return x * s; }

const int MaxN = int (1e5);

int main () {
	#ifdef lcl
		freopen (fname".in", "r", stdin);
		// freopen (fname".out", "w", stdout);
	#endif

	string s; cin >> s;
	int k;

	for (int i = 0; i < s.size(); ++i)
		if (s[i] == '^')
			k = i;

	ll L = 0, R = 0;

	for (int i = 0; i < k; ++i)
		L += s[i] == '=' ? 0 : (s[i] - '0') * (k - i);

	for (int i = k + 1; i < s.size(); ++i) {
		R += s[i] == '=' ? 0 : (s[i] - '0') * (i - k);
	}

	if (L > R)
		cout << "left";
	else
		if (L < R)
			cout << "right";
		else
			cout << "balance";
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin>>s;
    int mid=s.find('^');
    int l=s.length();
    long long int left=0,right=0;
    for(int i=mid-1;i>=0;i--)
    {
        if(s[i]!='=')left+=(s[i]-'0')*(mid-i);
    }
    for(int i=mid+1;i<l;i++)
    {
        if(s[i]!='=')right+=(s[i]-'0')*(i-mid);
    }
    if(left==right)printf("balance\n");
    else if(left>right)printf("left\n");
    else printf("right\n");
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <vector>
#include <algorithm>
#include <utility>
#include <map>
using namespace std;
int main()
{
    string s;
    cin>>s;
    int mid=s.find('^');
    int l=s.length();
    int left=0,right=0;
    for(int i=mid;i>=0;i--)
    {
        if(s[i]>='0' && s[i]<='9')left+=(s[i]-'0')*(mid-i);
    }
    for(int i=mid;i<l;i++)
    {
        if(s[i]>='0' && s[i]<='9')right+=(s[i]-'0')*(i-mid);
    }
    if(left==right)printf("balance\n");
    else if(left>right)printf("left\n");
    else printf("right\n");
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <vector>
#include <algorithm>
#include <utility>
#include <map>
using namespace std;
int main()
{
    string s;
    cin>>s;
    int mid=s.find('^');
    int l=s.length();
    int left=0,right=0;
    for(int i=mid-1;i>=0;i--)
    {
        if(s[i]>='0' && s[i]<='9')left+=(s[i]-'0')*(mid-i);
    }
    for(int i=mid+1;i<l;i++)
    {
        if(s[i]>='0' && s[i]<='9')right+=(s[i]-'0')*(i-mid);
    }
    if(left==right)printf("balance\n");
    else if(left>right)printf("left\n");
    else printf("right\n");
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin>>s;
    int mid=s.find('^');
    int l=s.length();
    int left=0,right=0;
    for(int i=mid-1;i>=0;i--)
    {
        if(s[i]!='=')left+=(s[i]-'0')*(mid-i);
    }
    for(int i=mid+1;i<l;i++)
    {
        if(s[i]!='=')right+=(s[i]-'0')*(i-mid);
    }
    if(left==right)printf("balance\n");
    else if(left>right)printf("left\n");
    else printf("right\n");
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <string>
#include <cmath>

using namespace std;

int main()
{
	string s;
	cin >> s;
	int n = s.size();
	int p = static_cast<int>( find(s.begin(), s.end(), '^') - s.begin() );
	int l = 0;
	for(int i=p-1; i>=0; --i)
		if(s[i]!='=')
			l += (p-i)*(s[i]-'0');
	int r = 0;
	for(int i=p+1; i<n; ++i)
		if(s[i]!='=')
			r += (i-p)*(s[i]-'0');
	cout << r << " " << l << endl;
	if(r>l)
		cout << "right" << endl;
	else if(l>r)
		cout << "left" << endl;
	else
		cout << "balanced" << endl;
	return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <string>
#include <cmath>

using namespace std;

int main()
{
	string s;
	cin >> s;
	int n = s.size();
	long long p = static_cast<long long>( find(s.begin(), s.end(), '^') - s.begin() );
	long long l = 0;
	for(long long i=p-1; i>=0; --i)
		if(s[i]!='=')
			l += (p-i)*static_cast<long long>(s[i]-'0');
	long long r = 0;
	for(long long i=p+1; i<n; ++i)
		if(s[i]!='=')
			r += (i-p)*static_cast<long long>(s[i]-'0');
	if(r>l)
		cout << "right" << endl;
	else if(l>r)
		cout << "left" << endl;
	else
		cout << "balance" << endl;
	return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <string>
#include <cmath>

using namespace std;

int main()
{
	string s;
	cin >> s;
	int n = s.size();
	int p = static_cast<int>( find(s.begin(), s.end(), '^') - s.begin() );
	int l = 0;
	for(int i=p-1; i>=0; --i)
		if(s[i]!='=')
			l += (p-i)*(s[i]-'0');
	int r = 0;
	for(int i=p+1; i<n; ++i)
		if(s[i]!='=')
			r += (i-p)*(s[i]-'0');
	if(r>l)
		cout << "right" << endl;
	else if(l>r)
		cout << "left" << endl;
	else
		cout << "balanced" << endl;
	return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <string>
#include <cmath>

using namespace std;

int main()
{
	string s;
	cin >> s;
	int n = s.size();
	int p = static_cast<int>( find(s.begin(), s.end(), '^') - s.begin() );
	int l = 0;
	for(int i=p-1; i>=0; --i)
		if(s[i]!='=')
			l += (p-i)*(s[i]-'0');
	int r = 0;
	for(int i=p+1; i<n; ++i)
		if(s[i]!='=')
			r += (i-p)*(s[i]-'0');
	if(r>l)
		cout << "right" << endl;
	else if(l>r)
		cout << "left" << endl;
	else
		cout << "balance" << endl;
	return 0;
}


#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<assert.h>
char *s;
int size;

int Is_bal()
{
    int pivot=-1;

    for(int i=0;i<size;i++)
    {
        if(s[i]=='^')
        {
            pivot=i;
            break;
        }
    }

    if(pivot ==-1)
    {return -2;}
    long long int torque_left=0,torque_right=0;
    int count=1;
    for(int i=pivot-1;i>=0;i--)
    {
        if(s[i]=='=')
        {
            count++;
            continue;
        }
        else
        {
            torque_left =torque_left+ (s[i]-'0')*(long long int)count;
            count++;
        }
    }
    count =1;
    for(int i=pivot+1;i<size;i++)
    {
        if(s[i]=='=')
        {
            count++;
            continue;
        }
        else
        {
            torque_right = torque_right+ (s[i]-'0')*(long long int)count;
            count++;
        }

    }

    if(torque_left == torque_right)
    return 0;

    if(torque_left > torque_right)
    return -1;

    if(torque_left < torque_right)
    return 1;

}

int main()
{

    s=(char *)calloc(1000010,sizeof(char));
    scanf("%s",s);

    size = strlen(s);

    int t=Is_bal();

    assert(t!=-2);

    if(t==0)
    printf("balance");
    if(t==-1)
    printf("left");
    if(t==1)
    printf("right");
}


#include <bits/stdc++.h>

#define FOR(i, a, b) for( int i = (a); i < (b); i++ )
#define ALL(A) A.begin(), A.end()
#define Set(a, s) memset(a, s, sizeof (a))
#define pb push_back
#define mp make_pair
typedef long long LL;

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
   // freopen("input.txt", "r" , stdin);
    string s;
    while(cin>>s)
    {
        int piv=-1;
        FOR(i,0,s.size())
            if(s[i]=='^')
                piv=i;
        LL r=0,l=0;
        for(LL i=1; i+piv<s.size() ; i++)
            if(isdigit(s[piv+i]))
            r += i*(LL)(s[piv+i]-'0');

        for(LL i=1; piv-i>=0 ; i++)
        if(isdigit(s[piv-i]))
            l += i*(LL)(s[piv-i]-'0');

        if(l==r)
            cout << "balance" <<endl;

        if(l>r)
            cout << "left" <<endl;

        if(l<r)
            cout << "right" <<endl;
    }
    return 0;
}


#include <iostream>
#include <cctype>
#include <string>

int main(){
    std::string s;
    std::cin >> s;
    long long check = 0, test = 0, count = 0;
    for (char ch : s){
        if (ch == '^') check = 1;
        else check += bool(check);
        if (!isdigit(ch)) continue;
        count += ch - '0';
        if (!check) test += count;
        else test -= (check - 1) * (ch - '0');
    }
    if (!test) puts("balance");
    else if (test > 0) puts("left");
    else puts("right");
}


#include <iostream>
#include <cctype>
#include <cstdio>
#include <string>

int main(){
	std::string s;
	std::cin >> s;
	long long check = 0, test = 0, count = 0;
	for (char ch : s){
		if (ch == '^') check = 1;
		else check += bool(check);
		if (isdigit(ch)) count += ch - '0';
		if (!check) test += count;
		else if (isdigit(ch)) test -= (check - 1) * (ch - '0');
	}
	if (!test) puts("balance");
	else if (test > 0) puts("left");
	else puts("right");
}


#include <iostream>
#include <cctype>
#include <cstdio>
#include <string>

int main(){
    std::string s;
    std::cin >> s;
    long long check = 0, test = 0, count = 0;
    for (char ch : s){
        if (ch == '^') check = 1;
        else check += bool(check);
        if (!isdigit(ch)) continue;
        count += ch - '0';
        if (!check) test += count;
        else test -= (check - 1) * (ch - '0');
    }
    if (!test) puts("balance");
    else if (test > 0) puts("left");
    else puts("right");
}


#include <iostream>
#include <string>
#include <cstring>
using namespace std;

int main() {
    long long int i,j,sum1 = 0,sum2 = 0;
    string s;
    int f;
    char c;
    cin >> s;
    int l = s.size();

    for (i = 0; i < l; i++) {
        if(s[i] == '^') {
            j = i;
            break;
        }
    }

    for (i = 0; i < l; i++) {
        c = s[i];
        if (c != '^' && f != 1) {
            if(c > 48 && c <= 57) {
                sum1 += (j-i) * (c-48);
            }
        }
        else if(1) {
            f = 1;
            if(c > 48 && c <= 57) {
                sum2 += (i-j) * (c-48);
            }
        }
    }

    if(sum1 == sum2)
        cout << "balance";
    else if(sum1 > sum2)
        cout << "left";
    else if(sum1 < sum2)
        cout << "right";
    return 0;
}


#include<cstring>
#include<string>
#include<cstdio>
#include<iostream>
using namespace std;
#define LL long long
string s;
int main(){
    int n, pos;
    cin>>s;
    n = s.length();
    for(int i = 0; s[i]; i++)
        if(s[ i ] == '^') {
            pos = i; break;
        }
    LL now = 1;
    LL l = 0, r = 0;
    for(int i = pos - 1; i >= 0; i--){
        if(s[ i ] != '=')
        {
            l +=  now * (LL)(s[ i ] - '0');
        }
        now++;
    }
    now = 1;
    for(int i = pos + 1; i < n; i++){
        if(s[ i ] != '=')
        {
            r += now * (LL)(s[ i ] - '0');
        }
        now++;
    }
    if( l > r ) cout<<"left\n";
    else if( l == r ) cout<<"balance\n";
    else cout<<"right\n";
    return 0;
}


#include<cstring>
#include<string>
#include<cstdio>
#include<iostream>
using namespace std;
#define LL long long
string s;
int main(){
    int n, pos;
    cin>>s;
    n = s.length();
    for(int i = 0; s[i]; i++)
        if(s[ i ] == '^') {
            pos = i; break;
        }
    LL now = 1;
    LL l = 0, r = 0;
    for(int i = pos - 1; i >= 0; i--){
        if(s[ i ] == '=') continue;
        else{
            l +=  now * (LL)(s[ i ] - '0');
        }
        now++;
    }
    now = 1;
    for(int i = pos + 1; i < n; i++){
        if(s[ i ] == '=') continue;
        else{
            r += now * (LL)(s[ i ] - '0');
        }
        now++;
    }
    if( l > r ) cout<<"left\n";
    else if( l == r ) cout<<"balance\n";
    else cout<<"right\n";
    return 0;
}


#include<iostream>
#include<vector>
#include<string>

using namespace std;

int main(){
    string s;
    cin >> s;

    long long leftweight = 0;
    long long rightweight = 0;
    long long pivot = 0;
    for (long long i = 0; i < s.size(); ++i){
        if (s[i] == '^') { pivot = i; break; }
    }

    for (int i = pivot - 1; i >= 0; --i){
        if (s[i] >= '0' && s[i] <= '9') { leftweight += (pivot - i)*(s[i] - 48); }
        if (s[i] == '=') continue;
    }

    for (int i = pivot + 1; i < s.size(); ++i){
        if (s[i] >= '0' && s[i] <= '9') { rightweight += (i - pivot)*(s[i] - 48); }
        if (s[i] == '=') continue;
    }

    if (leftweight == rightweight) { cout << "balance"; }
    if (leftweight < rightweight) { cout << "right"; }
    if (leftweight > rightweight) cout << "left";

    //system("pause");
    return 0;
}


#include<iostream>
#include<vector>
#include<string>

using namespace std;

typedef unsigned int ui;
int main(){
	string s;
	cin >> s;

	ui leftweight = 0;
	ui rightweight = 0;
	ui pivot = 0;
	for (int i = 0; i < s.size(); ++i){
		if (s[i] == '^') { pivot = i; break; }
	}

	for (int i = pivot; i >= 0; --i){
		if (s[i] >= '0' && s[i] <= '9') { leftweight += (pivot - i)*(s[i] - 48); }
		if (s[i] == '=') continue;
	}

	for (int i = pivot; i < s.size(); ++i){
		if (s[i] >= '0' && s[i] <= '9') { rightweight += (i - pivot)*(s[i] - 48); }
		if (s[i] == '=') continue;
	}

	if (leftweight == rightweight) { cout << "balance"; }
	if (leftweight < rightweight) { cout << "right"; }
	if (leftweight > rightweight) cout << "left";

	//system("pause");
	return 0;
}


#include<iostream>
#include<vector>
#include<string>

using namespace std;

typedef unsigned int ui;
int main(){
    string s;
    cin >> s;

    ui leftweight = 0;
    ui rightweight = 0;
    ui pivot = 0;
    for (int i = 0; i < s.size(); ++i){
        if (s[i] == '^') { pivot = i; break; }
    }

    for (int i = pivot - 1; i >= 0; --i){
        if (s[i] >= '0' && s[i] <= '9') { leftweight += (pivot - i)*(s[i] - 48); }
        if (s[i] == '=') continue;
    }

    for (int i = pivot + 1; i < s.size(); ++i){
        if (s[i] >= '0' && s[i] <= '9') { rightweight += (i - pivot)*(s[i] - 48); }
        if (s[i] == '=') continue;
    }

    //cout << "leftweight: " << leftweight<<endl;
    //cout << "rightweight: " << rightweight<<endl;
    if (leftweight == rightweight) { cout << "balance"; }
    if (leftweight < rightweight) { cout << "right"; }
    if (leftweight > rightweight) cout << "left";

    //system("pause");
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long  ll;
typedef unsigned long long ull;
typedef map <int, int> mii;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

#define maxn int(1e6 + 12)
#define maxb int(2e6 + 12)
#define inf int(1e9 + 7)
#define linf ll(1e18 + 12)
#define eps 1e-7
#define mp make_pair
#define pb push_back
//#define fn "a"
#define F first
#define S second

string s, l, r;
ll a, b;

int main()
{
    #ifdef fn
        freopen(fn".in", "r", stdin);
        freopen(fn".out", "w", stdout);
    #endif
    cin >> s;
    int k = int(s.find('^'));
    int n = int(s.size());
    l = s.substr(0, k);
    r = s.substr(k + 1, n - k - 1);
    reverse(l.begin(), l.end());
    for (int i = 0; i < int(l.size()); i++)
        if (l[i] != '=')
            a += (i + 1) * (l[i] - '0');
    for (int i = 0; i < int(r.size()); i++)
        if (r[i] != '=')
            b += (i + 1) * (r[i] - '0');
    if (a == b)
        puts("balance");
    else
        puts(a > b ? "left" : "right");
}


// прощай мое кресло XD

#include <iostream>
#include <cstdio>
#include <iomanip>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <cassert>
#include <cstring>
#include <sstream>
#include <ctime>
#include <stdexcept>
//#include <unordered_map>
//#include <unordered_set>

using namespace std;

#ifdef MY
#define assert2 assert
#else
#define assert2
#endif // MY

#define input_file(s) assert(freopen(s, "r", stdin))
#define output_file(s) assert(freopen(s, "w", stdout))
#define stderr_file(s) assert(freopen(s, "w", stderr))

#define TASK_FILE_NAME "join"

#define ALL(a) (a).begin(), (a).end()
#define FORAB(i, a, b) for (int i = a; i < b; ++i)

typedef unsigned uint;
typedef long long int64;
typedef unsigned long long uint64;
typedef pair<int, int> ipair;

const double PI = 3.14159265358979323846;
const double SQRT2 = 1.41421356237;
const double EPS = 1e-9;

const float SQRT2F = (float)SQRT2;

const int INF = 1e9;
const int64 INF64 = 1e18;

template<class T>
T sqr(const T &x) { return x * x; }

template<class T>
T min(const T &a, const T &b, const T &c) { return min(min(a, b), c); }

template<class T>
T max(const T &a, const T &b, const T &c) { return max(max(a, b), c); }

inline void yesno(bool y) { cout << (y? "YES\n" : "NO\n"); }
inline void yes_stop(bool y) { if (y) { yesno(1); exit(0); } }
inline void no_stop(bool y) { if (!y) { yesno(0); exit(0); } }

int gcd(int a, int b) { return b ? gcd (b, a % b) : a; }
int64 gcd(int64 a, int64 b) { return b ? gcd (b, a % b) : a; }

int sgn(int x) { return (x > 0) - (x < 0); }

class IManip {
public:
    virtual void perform(ostream &os) const {}
};

template<class It>
class ManipRangePrinter : public IManip {
private:
    const It b, e;

public:
    ManipRangePrinter(It _b, It _e): b(_b), e(_e) {}

    void perform(ostream &os) const {
        It g = b;
        if (g != e) os << *g;
        for (++g; g != e; ++g) {
            os << " " << *g;
        }
    }
};

ostream &operator<<(ostream &os, const IManip &man) {
    man.perform(os);
    return os;
}

template<class It>
ManipRangePrinter<It> range(It b, It e) { // stream manip
    return ManipRangePrinter<It>(b, e);
}

template<class It>
void print_range(ostream &os, It b, It e) {
    os << range(b, e);
}

template<class Container>
void print_container(ostream &os, Container &c) {
    return os << range(c.begin(), c.end());
}

// !GLOB

char s[1000000];

int main() {
    #ifdef MY
    input_file("input.txt");
    //output_file("output.txt");
    //stderr_file("stderr.txt");
    #else
    //input_file(TASK_FILE_NAME".in");
    //output_file(TASK_FILE_NAME".out");
    //input_file("input.txt");
    //output_file("output.txt");
    #endif

    ios_base::sync_with_stdio(0);

    // !MAIN

    gets(s);

    int l = strlen(s);

    int z = find(s, s + l, '^') - s;

    int m1 = 0, m2 = 0;

    for (int i = 0; i < z; ++i) {
        int k = z - i;
        if ('0' <= s[i] && s[i] <= '9') {
            m1 += (s[i] - '0') * k;
        }
    }

    for (int i = z + 1; i < l; ++i) {
        int k = i - z;
        if ('0' <= s[i] && s[i] <= '9') {
            m2 += (s[i] - '0') * k;
        }
    }

    if (m1 > m2) {
        cout << "left\n";
    } else if (m1 == m2) {
        cout << "balance\n";
    } else {
        cout << "right\n";
    }

    return 0;
}


// прощай мое кресло XD

#include <iostream>
#include <cstdio>
#include <iomanip>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <cassert>
#include <cstring>
#include <sstream>
#include <ctime>
#include <stdexcept>
//#include <unordered_map>
//#include <unordered_set>

using namespace std;

#ifdef MY
#define assert2 assert
#else
#define assert2
#endif // MY

#define input_file(s) assert(freopen(s, "r", stdin))
#define output_file(s) assert(freopen(s, "w", stdout))
#define stderr_file(s) assert(freopen(s, "w", stderr))

#define TASK_FILE_NAME "join"

#define ALL(a) (a).begin(), (a).end()
#define FORAB(i, a, b) for (int i = a; i < b; ++i)

typedef unsigned uint;
typedef long long int64;
typedef unsigned long long uint64;
typedef pair<int, int> ipair;

const double PI = 3.14159265358979323846;
const double SQRT2 = 1.41421356237;
const double EPS = 1e-9;

const float SQRT2F = (float)SQRT2;

const int INF = 1e9;
const int64 INF64 = 1e18;

template<class T>
T sqr(const T &x) { return x * x; }

template<class T>
T min(const T &a, const T &b, const T &c) { return min(min(a, b), c); }

template<class T>
T max(const T &a, const T &b, const T &c) { return max(max(a, b), c); }

inline void yesno(bool y) { cout << (y? "YES\n" : "NO\n"); }
inline void yes_stop(bool y) { if (y) { yesno(1); exit(0); } }
inline void no_stop(bool y) { if (!y) { yesno(0); exit(0); } }

int gcd(int a, int b) { return b ? gcd (b, a % b) : a; }
int64 gcd(int64 a, int64 b) { return b ? gcd (b, a % b) : a; }

int sgn(int x) { return (x > 0) - (x < 0); }

class IManip {
public:
    virtual void perform(ostream &os) const {}
};

template<class It>
class ManipRangePrinter : public IManip {
private:
    const It b, e;

public:
    ManipRangePrinter(It _b, It _e): b(_b), e(_e) {}

    void perform(ostream &os) const {
        It g = b;
        if (g != e) os << *g;
        for (++g; g != e; ++g) {
            os << " " << *g;
        }
    }
};

ostream &operator<<(ostream &os, const IManip &man) {
    man.perform(os);
    return os;
}

template<class It>
ManipRangePrinter<It> range(It b, It e) { // stream manip
    return ManipRangePrinter<It>(b, e);
}

template<class It>
void print_range(ostream &os, It b, It e) {
    os << range(b, e);
}

template<class Container>
void print_container(ostream &os, Container &c) {
    return os << range(c.begin(), c.end());
}

// !GLOB

char s[1100000];

int main() {
    #ifdef MY
    input_file("input.txt");
    //output_file("output.txt");
    //stderr_file("stderr.txt");
    #else
    //input_file(TASK_FILE_NAME".in");
    //output_file(TASK_FILE_NAME".out");
    //input_file("input.txt");
    //output_file("output.txt");
    #endif

    ios_base::sync_with_stdio(0);

    // !MAIN

    gets(s);

    int l = strlen(s);

    int z = find(s, s + l, '^') - s;

    int m1 = 0, m2 = 0;

    for (int i = 0; i < z; ++i) {
        int k = z - i;
        if ('0' <= s[i] && s[i] <= '9') {
            m1 += (s[i] - '0') * k;
        }
    }

    for (int i = z + 1; i < l; ++i) {
        int k = i - z;
        if ('0' <= s[i] && s[i] <= '9') {
            m2 += (s[i] - '0') * k;
        }
    }

    if (m1 > m2) {
        cout << "left\n";
    } else if (m1 == m2) {
        cout << "balance\n";
    } else {
        cout << "right\n";
    }

    return 0;
}


// прощай мое кресло XD

#include <iostream>
#include <cstdio>
#include <iomanip>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <cassert>
#include <cstring>
#include <sstream>
#include <ctime>
#include <stdexcept>
//#include <unordered_map>
//#include <unordered_set>

using namespace std;

#ifdef MY
#define assert2 assert
#else
#define assert2
#endif // MY

#define input_file(s) assert(freopen(s, "r", stdin))
#define output_file(s) assert(freopen(s, "w", stdout))
#define stderr_file(s) assert(freopen(s, "w", stderr))

#define TASK_FILE_NAME "join"

#define ALL(a) (a).begin(), (a).end()
#define FORAB(i, a, b) for (int i = a; i < b; ++i)

typedef unsigned uint;
typedef long long int64;
typedef unsigned long long uint64;
typedef pair<int, int> ipair;

const double PI = 3.14159265358979323846;
const double SQRT2 = 1.41421356237;
const double EPS = 1e-9;

const float SQRT2F = (float)SQRT2;

const int INF = 1e9;
const int64 INF64 = 1e18;

template<class T>
T sqr(const T &x) { return x * x; }

template<class T>
T min(const T &a, const T &b, const T &c) { return min(min(a, b), c); }

template<class T>
T max(const T &a, const T &b, const T &c) { return max(max(a, b), c); }

inline void yesno(bool y) { cout << (y? "YES\n" : "NO\n"); }
inline void yes_stop(bool y) { if (y) { yesno(1); exit(0); } }
inline void no_stop(bool y) { if (!y) { yesno(0); exit(0); } }

int gcd(int a, int b) { return b ? gcd (b, a % b) : a; }
int64 gcd(int64 a, int64 b) { return b ? gcd (b, a % b) : a; }

int sgn(int x) { return (x > 0) - (x < 0); }

class IManip {
public:
    virtual void perform(ostream &os) const {}
};

template<class It>
class ManipRangePrinter : public IManip {
private:
    const It b, e;

public:
    ManipRangePrinter(It _b, It _e): b(_b), e(_e) {}

    void perform(ostream &os) const {
        It g = b;
        if (g != e) os << *g;
        for (++g; g != e; ++g) {
            os << " " << *g;
        }
    }
};

ostream &operator<<(ostream &os, const IManip &man) {
    man.perform(os);
    return os;
}

template<class It>
ManipRangePrinter<It> range(It b, It e) { // stream manip
    return ManipRangePrinter<It>(b, e);
}

// !GLOB

char s[1100000];

int main() {
    #ifdef MY
    input_file("input.txt");
    //output_file("output.txt");
    //stderr_file("stderr.txt");
    #else
    //input_file(TASK_FILE_NAME".in");
    //output_file(TASK_FILE_NAME".out");
    //input_file("input.txt");
    //output_file("output.txt");
    #endif

    ios_base::sync_with_stdio(0);

    // !MAIN

    gets(s);

    int l = strlen(s);

    int z = find(s, s + l, '^') - s;

    int64 m1 = 0, m2 = 0;

    for (int i = 0; i < z; ++i) {
        int k = z - i;
        if ('0' <= s[i] && s[i] <= '9') {
            m1 += (s[i] - '0') * k;
        }
    }

    for (int i = z + 1; i < l; ++i) {
        int k = i - z;
        if ('0' <= s[i] && s[i] <= '9') {
            m2 += (s[i] - '0') * k;
        }
    }

    if (m1 > m2) {
        cout << "left\n";
    } else if (m1 == m2) {
        cout << "balance\n";
    } else {
        cout << "right\n";
    }

    return 0;
}


#include <iostream>
#include <sstream>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <list>
#include <bitset>
#include <algorithm>
#include <functional>
#include <cstring>
#include <numeric>
#include <iomanip>
#include <cmath>
#include <climits>
#include <cstring>
#include <cctype>

using namespace std;

typedef vector<int> vi;
typedef vector<vi > vvi;
typedef pair<int,int> ii;
typedef vector<ii > vii;
typedef vector<vii > vvii;
typedef set<ii > sii;
int mov[4][2] = {-1, 0, 0, 1, 1, 0, 0, -1,};

#define pb push_back
#define mp(a, b) make_pair((a), (b))
#define all(c) (c).begin(),(c).end()
#define PI (acos(-1))
#define EPS 1e-7
#define INF 1000000000
#define MOD 1000000007
// #define CUS_DEBUG

#ifdef CUS_DEBUG
#include "debug.h"
#else
#define debug(a)
#define debug_array(a, n)
#define debug_array2(a, n, m)
#endif

template<typename T>
struct number_iterator : std::iterator<random_access_iterator_tag, T>{
	T v;
	number_iterator(T _v) : v(_v) {}
	operator T&(){return v;}
	T operator *() const {return v;}
};
template <typename T>
struct number_range {
	T b,e;
	number_range(T b, T e):b(b),e(e){}
	number_iterator<T> begin(){return b;}
	number_iterator<T> end(){return e;}
};
template<typename T> number_range<T> range(T e) {return number_range<T>(0, e);}
template<typename T> number_range<T> range(T b, T e) {return number_range<T>(b, e);}

long long get_weight(string str)
{
	int n = str.size();
	long long total = 0ll;

	for (auto i: range(n)) {
		char ch = str[i];
		if ('0' <= ch && ch <= '9') {
			long long d = ch - '0';
			total += d * (i + 1);
		}
	}

	return total;
}

int main()
{
	string str;
	cin >> str;
	auto pos = str.find("^");
	string L = str.substr(0, pos);
	string R = str.substr(pos + 1, str.size() - pos - 1);
	reverse(all(L));
	auto wl = get_weight(L);
	auto wr = get_weight(R);
	if (wl == wr)
		cout << "balance" << endl;
	else if (wl < wr)
		cout << "right" << endl;
	else
		cout << "left" << endl;
	return 0;
}


#include <iostream>
#include <iterator>
#include <fstream>
#include <sstream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <utility>
#include <map>
#include <set>

using namespace std;

typedef pair<int,int> PII;

class solution
{
    void virtual run() { }
public:
    void start(bool debug = false) {
        if (debug) {
            //freopen("D:\\Projects\\codeforces\\codeforces\\input.txt", "r", stdin);
            //freopen("D:\\Projects\\codeforces\\codeforces\\output.txt", "w", stdout);
        }
        run();
    }
};

class A : public solution
{
public:
    void run()
    {
        std::string line;
        //line.resize(1000000);
        std::getline(std::cin, line);
        //std::cout << line;
        int pos = line.find('^');
        long long res = 0;
        for (int first = pos - 1, last = pos + 1;
             first > -1 && last < line.size(); ++last, --first)
        {
            res += line[first] == '=' ? 0 : (line[first] - '0') * (first - pos);
            res += line[last] == '=' ? 0 : (line[last] - '0') * (last - pos);
        }
        if (!res) std::cout << "balance" << std::endl;
        else std::cout << (res > 0 ? "right" : "left") << std::endl;
    }
};

int main()
{
    solution a = A();
    a.start(true);

    return EXIT_SUCCESS;
}


#include <iostream>
#include <iterator>
#include <fstream>
#include <sstream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <utility>
#include <map>
#include <set>

using namespace std;

typedef pair<int,int> PII;

class solution
{
public:
    void start(bool debug = false) {
        if (debug)
		{
            freopen("input.txt", "r", stdin);
            freopen("output.txt", "w", stdout);
        }
        run();
    }
	void virtual run() { }
};

class A : public solution
{
public:
    void run()
    {
		std::string line;
        line.resize(1000000);
        std::getline(std::cin, line);
        int pos = line.find('^');
        long long res = 0;

		for (int first = 0; first < pos; ++first)
            res += line[first] == '=' ? 0 : (line[first] - '0') * (first - pos);

		for (int last = pos + 1; last < line.size(); ++last)
            res += line[last] == '=' ? 0 : (line[last] - '0') * (last - pos);

        if (!res) std::cout << "balance" << std::endl;
        else std::cout << (res > 0 ? "right" : "left") << std::endl;
    }
};

int main()
{
    A a;
    a.run();

    return EXIT_SUCCESS;
}


//by maximumSHOT

#define _USE_MATH_DEFINES

#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
//#include <conio.h>
#include <queue>
#include <map>
#include <set>
#include <time.h>
#include <clocale>
#include <fstream>

using namespace std;

#define forx(i,n) for(int i(0);i < n;i++)
#define vec vector

typedef long L;
typedef long long LL;
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef vector<double> vdouble;
typedef vector<vector<double>> vvdouble;
typedef vec<bool> vbool;
typedef vec<vec<bool>> vvbool;
typedef pair<int,int> pii;
typedef pair<double,double> pdd;
typedef pair<double,int> pdi;
typedef pair<int,double> pid;
typedef unsigned long long ull;
typedef unsigned int ui;
const int inf = 1000 * 1000 * 1000;
const LL inf64 = LL(inf) * inf;

int main(int argc,char **argv)
{
    ios_base::sync_with_stdio(0);

    string lev;
    int suml(0),sumr(0),dl(0),dr(0);
    getline(cin,lev);
    int q = lev.find("^");

    for(int i(q);i >= 0;i--)
    {
        if(lev[i] >= '1' && lev[i] <= '9')
        {
            suml+= dl*((int)(lev[i]) - 48);
        }
        dl++;
    }

    for(int i(q);i < lev.length();i++)
    {
        if(lev[i] >= '1' && lev[i] <= '9')
        {
            sumr += dr*((int)(lev[i] - 48));
        }
        dr++;
    }

    if(suml == sumr)
    {
        cout << "balance";
    }else
    {
        if(suml < sumr)
        {
            cout << "right";
        }else
        {
            cout << "left";
        }
    }

    //_getch();
    return 0;
}


//by maximumSHOT

#define _USE_MATH_DEFINES

#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <conio.h>
#include <queue>
#include <map>
#include <set>
#include <time.h>
#include <clocale>
#include <fstream>

using namespace std;

#define forx(i,n) for(int i(0);i < n;i++)
#define vec vector

typedef long L;
typedef long long LL;
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef vector<double> vdouble;
typedef vector<vector<double>> vvdouble;
typedef vec<bool> vbool;
typedef vec<vec<bool>> vvbool;
typedef pair<int,int> pii;
typedef pair<double,double> pdd;
typedef pair<double,int> pdi;
typedef pair<int,double> pid;
typedef unsigned long long ull;
typedef unsigned int ui;
const int inf = 1000 * 1000 * 1000;
const LL inf64 = LL(inf) * inf;

int main(int argc,char **argv)
{
    ios_base::sync_with_stdio(0);

    string lev;
    LL suml(0),sumr(0),dl(0),dr(0);
    getline(cin,lev);
    LL q = lev.find("^");

    for(LL i(q);i >= 0;i--)
    {
        if(lev[i] >= '1' && lev[i] <= '9')
        {
            suml+= dl*((LL)(lev[i]) - 48);
        }
        dl++;
    }

    for(LL i(q);i < lev.length();i++)
    {
        if(lev[i] >= '1' && lev[i] <= '9')
        {
            sumr += dr*((LL)(lev[i] - 48));
        }
        dr++;
    }

    if(suml == sumr)
    {
        cout << "balance";
    }else
    {
        if(suml < sumr)
        {
            cout << "right";
        }else
        {
            cout << "left";
        }
    }

    _getch();
    return 0;
}


//by maximumSHOT

#define _USE_MATH_DEFINES

#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
//#include <conio.h>
#include <queue>
#include <map>
#include <set>
#include <time.h>
#include <clocale>
#include <fstream>

using namespace std;

#define forx(i,n) for(int i(0);i < n;i++)
#define vec vector

typedef long L;
typedef long long LL;
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef vector<double> vdouble;
typedef vector<vector<double>> vvdouble;
typedef vec<bool> vbool;
typedef vec<vec<bool>> vvbool;
typedef pair<int,int> pii;
typedef pair<double,double> pdd;
typedef pair<double,int> pdi;
typedef pair<int,double> pid;
typedef unsigned long long ull;
typedef unsigned int ui;
const int inf = 1000 * 1000 * 1000;
const LL inf64 = LL(inf) * inf;

int main(int argc,char **argv)
{
    ios_base::sync_with_stdio(0);

    string lev;
    LL suml(0),sumr(0),dl(0),dr(0);
    getline(cin,lev);
    LL q = lev.find("^");

    for(LL i(q);i >= 0;i--)
    {
        if(lev[i] >= '1' && lev[i] <= '9')
        {
            suml+= dl*((LL)(lev[i]) - 48);
        }
        dl++;
    }

    for(LL i(q);i < lev.length();i++)
    {
        if(lev[i] >= '1' && lev[i] <= '9')
        {
            sumr += dr*((LL)(lev[i] - 48));
        }
        dr++;
    }

    if(suml == sumr)
    {
        cout << "balance";
    }else
    {
        if(suml < sumr)
        {
            cout << "right";
        }else
        {
            cout << "left";
        }
    }

    //_getch();
    return 0;
}


#include<iostream>
#include<string>

using namespace std;

typedef long long ll;

int main(){
  string s;
  cin >> s;

  int pos=0;
  while(s[pos]!='^')++pos;

  ll left=0;
  for(int i=0;i<pos;++i)
    if(s[i]!='=')
      left+=(s[i]-'0')*(pos-i);

  ll right=0;
  for(int i=pos+1;i<int(s.size());++i)
    if(s[i]!='=')
      right+=(s[i]-'0')*(i-pos);

  if(left==right)
    cout << "balance\n";
  else if(left<right)
    cout << "right\n";
  else
    cout << "left\n";

}


#include <bits/stdc++.h>

using namespace std;

string s;
int i, lef, rig, edge, pivot;

int main() {
	cin >> s;
	pivot = s.find( '^' );
	edge = s.size();
	lef = 0;
	rig = 0;
	for( i = 0; i < pivot; i++ )
		if( s[i] != '=' )
			lef += ( s[i] - '0' ) * ( pivot - i );
	for( i = pivot + 1; i < edge; i++ )
		if( s[i] != '=' )
			rig += ( s[i] - '0' ) * ( i - pivot );
	if( lef > rig )
		cout << "left" << endl;
	else if( lef < rig )
		cout << "right" << endl;
	else
		cout << "balance" << endl;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

string s;
int i, edge, pivot;
long long lef, rig;

int main() {
	cin >> s;
	pivot = s.find( '^' );
	edge = s.size();
	lef = 0;
	rig = 0;
	for( i = 0; i < pivot; i++ )
		if( s[i] != '=' )
			lef += ( s[i] - '0' ) * ( pivot - i );
	for( i = pivot + 1; i < edge; i++ )
		if( s[i] != '=' )
			rig += ( s[i] - '0' ) * ( i - pivot );
	if( lef > rig )
		cout << "left" << endl;
	else if( lef < rig )
		cout << "right" << endl;
	else
		cout << "balance" << endl;
	return 0;
}


#include <vector>
#include <set>
#include <iomanip>
#include <bitset>
#include <iostream>
#include<algorithm>
#include<string>
#include<map>
using namespace std;

int main() {
    string s;
    cin>>s;
    int sum=0,summ=0;
    int i=s.find('^');
    for (int q=0 ;q<i;q++){
        if (s[q]!='='){
            sum+=(i-q)*(s[q]-'0');

        }

    }
    for (int q=s.size()-1 ;q>i;q--){
            if (s[q]!='='){
                summ+=(q-i)*(s[q]-'0');
            }
        }

     if (sum==summ)cout<<"balance";
            else if (sum >summ)cout<<"left";
                    else cout<< "right";
}


#include <vector>
#include <set>
#include <iomanip>
#include <bitset>
#include <iostream>
#include<algorithm>
#include<string>
#include<map>
using namespace std;

int main() {
    string s;
    cin>>s;
    int i=0,ss,sss;
    int w=0,q=0;
    pair<int ,int > a[10000];
    pair<int ,int > b[10000];
    while(s[i]!='^'){
        if (s[i]!='='){
            a[w].first=s[i]-'0';
a[w++].second=i;
        }
        i++;
        }
        ss=i;
        i=s.size()-1;
        while(s[i]!='^'){
                if (s[i]!='='){
                    b[q].first=s[i]-'0';
        b[q++].second=i;
                }
        i--;
    }
        sss=i;int sum=0,summ=0;
        for(int j = 0 ;j<w;j++){
            sum+=a[j].first*(ss-a[j].second);
        }
        for(int j = 0 ;j<q;j++){
                    summ+=b[j].first*(b[j].second-sss);
                }
        if (sum==summ)cout<<"balance";
        else if (sum >summ)cout<<"left";
                else cout<< "right";

}


#include <vector>
#include <set>
#include <iomanip>
#include <bitset>
#include <iostream>
#include<algorithm>
#include<string>
#include<map>
using namespace std;

int main() {
    string s;
    cin>>s;
    int sum=0,summ=0;
    int i=s.find("^");
    int j=s.rfind("^");
    for (int q=0 ;q<i;q++){
        if (s[q]!='='){
            sum+=(i-q)*(s[q]-'0');

        }

    }
    for (int q=s.size()-1 ;q>j;q--){
            if (s[q]!='='){
                summ+=(q-j)*(s[q]-'0');
            }
        }

     if (sum==summ)cout<<"balance";
            else if (sum >summ)cout<<"left";
                    else cout<< "right";
}


#include <vector>
#include <set>
#include <iomanip>
#include <bitset>
#include <iostream>
#include<algorithm>
#include<string>
#include<map>
using namespace std;

int main() {
	string s;
	cin>>s;
	long long int sum=0,summ=0;
	int i=s.find('^');
	for (int q=0 ;q<i;q++){
		if (s[q]!='='){
			sum+=(i-q)*(s[q]-'0');

		}

	}
	for (int q=s.size()-1 ;q>i;q--){
			if (s[q]!='='){
				summ+=(q-i)*(s[q]-'0');
			}
		}

	 if (sum==summ)cout<<"balance";
	        else if (sum >summ)cout<<"left";
	                else cout<< "right";
}


#include <vector>
#include <set>
#include <iomanip>
#include <bitset>
#include <iostream>
#include<algorithm>
#include<string>
#include<map>
using namespace std;

int main() {
    string s;
    cin>>s;
    int sum=0,summ=0;
    int i=s.find("^");
    for (int q=0 ;q<i;q++){
        if (s[q]!='='){
            sum+=(i-q)*(s[q]-'0');

        }

    }
    for (int q=s.size()-1 ;q>i;q--){
            if (s[q]!='='){
                summ+=(q-i)*(s[q]-'0');
            }
        }

     if (sum==summ)cout<<"balance";
            else if (sum >summ)cout<<"left";
                    else cout<< "right";
}


#include <iostream>
#include <string>

int main(void) {
    std::string s;
    std::cin >> s;

    std::string first = s.substr(0, s.find('^'));
    std::string second = s.substr(s.find('^') + 1);

    __int64 sum1 = 0;
    __int64 sum2 = 0;

    __int64 dist;
    std::string::const_reverse_iterator it;
    for (dist = 1, it = first.rbegin(); it != first.rend(); dist++, it++) {
        int weight;
        if (*it == '=')
            weight = 0;
        else
            weight = *it - '0';
        sum1 += weight * dist;
    }

    std::string::const_iterator it2;
    for (dist = 1, it2 = second.begin(); it2 != second.end(); dist++, it2++) {
        int weight;
        if (*it2 == '=')
            weight = 0;
        else
            weight = *it2 - '0';
        sum2 += weight * dist;
    }

    if (sum2 == sum1)
        std::cout << "balance" << std::endl;
    else if (sum1 > sum2)
        std::cout << "left" << std::endl;
    else
        std::cout << "right" << std::endl;

    return 0;
}


#include <iostream>
#include <string>
#include <cstdio>

using namespace std;

int main(){
	// freopen("in.txt", "r", stdin);
	string s1, s2;
	getline(cin, s1, '^');
	getline(cin, s2);
	long long lx = 0, rx = 0;
	for(int i = 0; i < s1.size(); ++i){
		if(s1[i] >= '0' && s1[i] <='9'){
			lx += (s1[i] - '0') * (s1.size() - i);
		}
	}
	for(int i = 0; i < s2.size(); ++i){
		if(s2[i] >= '0' && s2[i] <='9'){
			rx += (s2[i] - '0') * (i + 1);
		}
	}
	if(lx == rx) cout << "balance";
	else if(lx < rx) cout << "right";
	else cout << "left";
	return 0;
}


#include <iostream>
#include <string>
#include <cstdio>

using namespace std;

int main(){
	// freopen("in.txt", "r", stdin);
	string s1, s2;
	getline(cin, s1, '^');
	getline(cin, s2);
	int lx = 0, rx = 0;
	for(int i = 0; i < s1.size(); ++i){
		if(s1[i] >= '0' && s1[i] <='9'){
			lx += (s1[i] - '0') * (s1.size() - i);
		}
	}
	for(int i = 0; i < s2.size(); ++i){
		if(s2[i] >= '0' && s2[i] <='9'){
			rx += (s2[i] - '0') * (i + 1);
		}
	}
	if(lx == rx) cout << "balance";
	else if(lx < rx) cout << "right";
	else cout << "left";
	return 0;
}


#include<iostream>
#include<cmath>
#include<cstdio>
#include<algorithm>
#include<vector>

using namespace std;

#define INF 999999999

int main(){
	char str[1000001];
	cin >> str;

	int bar[2] ={};
	int center=0;

	for (int i=0; str[i] != '\0'; i++){
		if(str[i] == '^')center = i;
	}
	for (int j=0; j <center; j++){
		if(str[j] != '='){
			bar[0] += (center - j) * (str[j] - '0');
		}
	}
	for (int k=center+1;  str[k] != '\0'; k++){
		if(str[k] != '='){
			bar[1] += (k - center) * (str[k] - '0');
		}
	}

	if(bar[0] == bar[1]){
		cout << "balance" << endl;
	}
	else if (bar[0] > bar[1]){
		cout << "left" << endl;
	}
	else {
		cout << "right" << endl;
	}

	return 0;
}


#include<iostream>
#include<cmath>
#include<cstdio>
#include<algorithm>
#include<vector>

using namespace std;

#define INF 999999999

int main(){
	char str[1000001];
	cin >> str;

	long long int bar[2] ={};
	int center=0;

	for (int i=0; str[i] != '\0'; i++){
		if(str[i] == '^')center = i;
	}
	for (int j=0; j <center; j++){
		if(str[j] != '='){
			bar[0] += (long long int)(center - j) * (long long int)(str[j] - '0');
		}
	}
	for (int k=center+1;  str[k] != '\0'; k++){
		if(str[k] != '='){
			bar[1] += (long long int)(k - center) * (long long int)(str[k] - '0');
		}
	}

	if(bar[0] == bar[1]){
		cout << "balance" << endl;
	}
	else if (bar[0] > bar[1]){
		cout << "left" << endl;
	}
	else {
		cout << "right" << endl;
	}

	return 0;
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <ctime>
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define sz(c) (c).size()
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define tr(c, i) for(__typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define present(c, x) ((c).find(x) != (c).end())
#define cpresent(c, x) (find(all(c), x) != (c).end())
#define REP(i, n) for(int i = 0; i < (n); i++)
#define REPD(i, n) for(int i = (n)-1; i >= 0; i--)
#define FOR(i, a, b) for(int i = (a); i <= (b); i++)
#define FORD(i, a, b) for(int i = (a); i >= (b); i--)
#define mp make_pair
#define CHECK(S, j) (S & (1 << j))
#define SET(S, j) (S |= (1 << j))
#define SETALL(S, j) (S = (1 << j)-1)
#define UNSET(S, j) (S &= ~(1 << j))
#define TOGGLE(S, j) (S ^= (1 << j))
template<class T>string tostring(T t){stringstream s;s<<t;return s.str();}

int main(){
    string s;
    cin >> s;
    int total = 0, mid = s.find_first_of('^');
    REP(i, sz(s)){
        if(s[i]!= '=' && s[i] != '^'){
            total += (s[i]-'0')*(mid-i);
        }
    }
    if(total == 0) cout << "balance";
    else if(total > 0) cout << "left";
    else cout << "right";
    return 0;
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <ctime>
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define sz(c) (c).size()
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define tr(c, i) for(__typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define present(c, x) ((c).find(x) != (c).end())
#define cpresent(c, x) (find(all(c), x) != (c).end())
#define REP(i, n) for(int i = 0; i < (n); i++)
#define REPD(i, n) for(int i = (n)-1; i >= 0; i--)
#define FOR(i, a, b) for(int i = (a); i <= (b); i++)
#define FORD(i, a, b) for(int i = (a); i >= (b); i--)
#define mp make_pair
#define CHECK(S, j) (S & (1 << j))
#define SET(S, j) (S |= (1 << j))
#define SETALL(S, j) (S = (1 << j)-1)
#define UNSET(S, j) (S &= ~(1 << j))
#define TOGGLE(S, j) (S ^= (1 << j))
template<class T>string tostring(T t){stringstream s;s<<t;return s.str();}

int main(){
    string s;
    cin >> s;
    int total = 0, mid = s.find_first_of('^');
    REP(i, sz(s)){
        int value = 0;
        if(isalnum(s[i])){
            value = s[i]-'0';
        }
        total += value*(mid-i);
    }
    if(total == 0) cout << "balance";
    else if(total > 0) cout << "left";
    else cout << "right";
    return 0;
}


#include<stdio.h>
#include<string>
#include<iostream>
#include<math.h>
#include<map>
#include<string.h>
#include<algorithm>
using namespace std;
#define LL __int64
const int maxm=1e5+10;
LL a[maxm];
map<LL,LL>vis;
map<LL,LL>p;
map<LL,LL>q;
LL pow()
{
    LL sum=1;
    for(LL i=1; i<=31; i++)
    {
        sum<<=1;
        p[i]=sum;
    }
}
int main()
{
    LL n;
    p.clear();
    pow();
    while(scanf("%I64d",&n)!=EOF)
    {
        vis.clear();
        q.clear();
        for(LL i=0; i<n; i++)
        {
            scanf("%I64d",&a[i]);
            vis[a[i]]++;
        }
        sort(a,a+n);
        LL ans=0;
        for(LL i=0; i<n; i++)
        {
            for(LL j=1; j<=31; j++)
            {
                if(vis[p[j]-a[i]]&&p[j]-a[i]>=a[i]&&vis[a[i]]>1)
                {
                    ans+=((vis[a[i]])*(vis[a[i]]-1))/2;
//                    printf("%I64d %I64d\n",p[j]-a[i],a[i]);
                    i+=(vis[a[i]]-1);
                    break;
                }
                else if(vis[p[j]-a[i]]&&p[j]-a[i]>a[i]&&vis[a[i]]==1)
                {
                    ans++;
//                    printf("%I64d %I64d\n",p[j]-a[i],a[i]);
                }
            }
        }
        printf("%d\n",ans);
    }
    return 0;
}


#include<stdio.h>
#include<string>
#include<iostream>
#include<math.h>
#include<map>
#include<string.h>
#include<algorithm>
using namespace std;
#define LL __int64
const int maxm=1e5+10;
LL a[maxm];
map<LL,LL>vis;
map<LL,LL>p;
map<LL,LL>q;
LL pow()
{
    LL sum=1;
    for(LL i=1; i<=31; i++)
    {
        sum<<=1;
        p[i]=sum;
    }
}
int main()
{
    LL n;
    p.clear();
    pow();
    while(scanf("%I64d",&n)!=EOF)
    {
        vis.clear();
        q.clear();
        for(LL i=0; i<n; i++)
        {
            scanf("%I64d",&a[i]);
            vis[a[i]]++;
        }
        sort(a,a+n);
        LL ans=0;
        for(LL i=0; i<n; i++)
        {
            for(LL j=1; j<=31; j++)
            {
                if(p[j]>a[i]&&vis[p[j]-a[i]]&&p[j]-a[i]>=a[i]&&vis[a[i]]>1)
                {
                    ans++;
//                    printf("%I64d %I64d\n",p[j]-a[i],a[i]);
                }else if(p[j]>a[i]&&vis[p[j]-a[i]]&&p[j]-a[i]>a[i]&&vis[a[i]]==1)
                {
                    ans++;
//                    printf("%I64d %I64d\n",p[j]-a[i],a[i]);
                }
            }
        }
        printf("%d\n",ans);
    }
    return 0;
}


#include<stdio.h>
#include<string>
#include<iostream>
#include<math.h>
#include<map>
#include<string.h>
#include<algorithm>
using namespace std;
#define LL __int64
const int maxm=1e5+10;
LL a[maxm];
map<LL,LL>vis;
map<LL,LL>p;
map<LL,LL>q;
LL pow()
{
    LL sum=1;
    for(LL i=1; i<=32; i++)
    {
        sum<<=1;
        p[i]=sum;
    }
}
int main()
{
    LL n;
    p.clear();
    pow();
    while(scanf("%I64d",&n)!=EOF)
    {
        vis.clear();
        q.clear();
        for(LL i=0; i<n; i++)
        {
            scanf("%I64d",&a[i]);
            vis[a[i]]++;
        }
        sort(a,a+n);
        LL ans=0;

        for(LL j=1; j<=32; j++)
        {
            for(LL i=0; i<n; i++)
            {
                if(vis[p[j]-a[i]]&&p[j]-a[i]==a[i]&&vis[a[i]]>1)
                {

                    ans+=((vis[a[i]])*(vis[a[i]]-1))/2;
//                    printf("%I64d %I64d\n",p[j]-a[i],a[i]);
                    i+=vis[a[i]];
                }
                else if(vis[p[j]-a[i]]&&p[j]-a[i]>a[i]&&vis[a[i]]==1)
                {
                    ans++;
//                    printf("%I64d %I64d\n",p[j]-a[i],a[i]);
                }
            }
        }

        printf("%d\n",ans);
    }
    return 0;
}


#include<stdio.h>
#include<string>
#include<iostream>
#include<math.h>
#include<map>
#include<string.h>
#include<algorithm>
using namespace std;
#define LL __int64
const int maxm=1e5+10;
LL a[maxm];
map<LL,LL>vis;
map<LL,LL>p;
map<LL,LL>q;
LL pow()
{
    LL sum=1;
    for(LL i=1; i<=32; i++)
    {
        sum<<=1;
        p[i]=sum;
    }
}
int main()
{
    LL n;
    p.clear();
    pow();
    while(scanf("%I64d",&n)!=EOF)
    {
        vis.clear();
        q.clear();
        for(LL i=0; i<n; i++)
        {
            scanf("%I64d",&a[i]);
            vis[a[i]]++;
        }
        sort(a,a+n);
        LL ans=0;
        for(LL i=0; i<n; i++)
        {
            for(LL j=1; j<=32; j++)
            {
                if(vis[p[j]-a[i]]&&p[j]-a[i]==a[i]&&vis[a[i]]>1)
                {
                    ans+=((vis[a[i]])*(vis[a[i]]+1))/2;
//                    printf("%I64d %I64d\n",p[j]-a[i],a[i]);
                    i+=(vis[a[i]]);
                    break;
                }
                else if(vis[p[j]-a[i]]&&p[j]-a[i]>a[i]&&vis[a[i]]==1)
                {
                    ans++;
//                    printf("%I64d %I64d\n",p[j]-a[i],a[i]);
                }
            }
        }
        printf("%d\n",ans);
    }
    return 0;
}


#include<stdio.h>
#include<string>
#include<iostream>
#include<math.h>
#include<map>
#include<string.h>
#include<algorithm>
using namespace std;
#define LL __int64
const int maxm=1e5+10;
LL a[maxm];
map<LL,LL>vis;
map<LL,LL>p;
map<LL,LL>q;
LL pow()
{
    LL sum=1;
    for(LL i=1; i<=32; i++)
    {
        sum<<=1;
        p[i]=sum;
    }
}
int main()
{
    LL n;
    p.clear();
    pow();
    while(scanf("%I64d",&n)!=EOF)
    {
        vis.clear();
        q.clear();
        for(LL i=0; i<n; i++)
        {
            scanf("%I64d",&a[i]);
            vis[a[i]]++;
        }
        sort(a,a+n);
        LL ans=0;
        for(LL i=0; i<n; i++)
        {
            for(LL j=1; j<=32; j++)
            {
                if(vis[p[j]-a[i]]&&p[j]-a[i]==a[i]&&vis[a[i]]>1)
                {
                    ans+=((vis[a[i]])*(vis[a[i]]-1))/2;
//                    printf("%I64d %I64d\n",p[j]-a[i],a[i]);
                    i+=(vis[a[i]]);
                    break;
                }
                else if(vis[p[j]-a[i]]&&p[j]-a[i]>a[i]&&vis[a[i]])
                {
                    ans++;
//                    printf("%I64d %I64d\n",p[j]-a[i],a[i]);
                }
            }
        }
        printf("%d\n",ans);
    }
    return 0;
}


#include "bits/stdc++.h"
#define ll __int64
using namespace std;
bool evenpower(int x)
{
    if (x==0)
    {
        return false;
    }
    if ((x&(x-1))==0)
    {
        return true;
    }
    else
        return false;
}
map<int,int>arr;
int main()
{
   ios::sync_with_stdio(0); cin.tie(0);
  int m,key,count=0;
  cin>>m;
  std::vector<int> odd ,even;
  for (int i = 0; i < m; ++i)
  {
      scanf("%d",&key);
      if (key&1)
      {
          odd.push_back(key);
      }
      else
        even.push_back(key);
  }

  for (int i = 0; i < odd.size(); ++i)
  {
      for (int j = i+1; j < odd.size(); ++j)
      {
        int temp=odd[i]+odd[j];
          if (evenpower(temp))
          {
              count++;
          }
      }
  }

  for (int i = 0; i < even.size(); ++i)
  {
      for (int j = i+1; j < even.size(); ++j)
      {
        int temp=even[i]+even[j];
          if (evenpower(temp))
          {
              count++;
          }
      }
  }
printf("%d\n", count);

    return 0;
}


#include "bits/stdc++.h"
#define ll __int64
using namespace std;
bool evenpower(int x)
{
    if (x==0)
    {
        return false;
    }
    if ((x&(x-1))==0)
    {
        return true;
    }
    else
        return false;
}
map<int,int>arr;
int main()
{
  // ios::sync_with_stdio(0); cin.tie(0);
  int m,key,count=0;
  cin>>m;
  std::vector<int> odd ,even;
  for (int i = 0; i < m; ++i)
  {
      scanf("%d",&key);
      if (key&1)
      {
          odd.push_back(key);
      }
      else
        even.push_back(key);
  }

  for (int i = 0; i < odd.size(); ++i)
  {
      for (int j = i+1; j < odd.size(); ++j)
      {
        int temp=odd[i]+odd[j];
          if (evenpower(temp))
          {
              count++;
          }
      }
  }

  for (int i = 0; i < even.size(); ++i)
  {
      for (int j = i+1; j < even.size(); ++j)
      {
        int temp=even[i]+even[j];
          if (evenpower(temp))
          {
              count++;
          }
      }
  }
printf("%d\n", count);

    return 0;
}


#include "bits/stdc++.h"
#define ll __int64
using namespace std;
std::vector<int> power;
void fuc()
{
    for (int i = 0; i < 32; ++i)
    {
        power.push_back((1<<i));
    }
}
int main()
{
    fuc();

 long long m,key,count=0;
  cin>>m;
  std::vector<int> odd ;
  for (int i = 0; i < m; ++i)
  {
      scanf("%d",&key);

          odd.push_back(key);

  }
    sort(odd.begin(),odd.end());
  for (int i = 0; i < odd.size(); ++i)
  {
    for (int j = 0; j < power.size(); ++j)
    {

       int temp=power[j]-odd[i];
       int start_index=lower_bound(odd.begin()+i+1,odd.end(),temp)-odd.begin();
       int last_index=upper_bound(odd.begin()+i+1,odd.end(),temp)-odd.begin();
       count+=last_index-start_index;
    }

  }
printf("%d\n", count);

    return 0;
}


#include "bits/stdc++.h"
#define ll __int64
using namespace std;
bool evenpower(int x)
{
    if (x==0)
    {
        return false;
    }
    if ((x&(x-1))==0)
    {
        return true;
    }
    else
        return false;
}
map<int,int>arr;
int main()
{
  int m,key,count=0;
  cin>>m;
  std::vector<int> odd ,even;
  for (int i = 0; i < m; ++i)
  {
      cin>>key;
      if (key&1)
      {
          odd.push_back(key);
      }
      else
        even.push_back(key);
  }

  for (int i = 0; i < odd.size(); ++i)
  {
      for (int j = i+1; j < odd.size(); ++j)
      {
        int temp=odd[i]+odd[j];
          if (evenpower(temp))
          {
              count++;
          }
      }
  }

  for (int i = 0; i < even.size(); ++i)
  {
      for (int j = i+1; j < even.size(); ++j)
      {
        int temp=even[i]+even[j];
          if (evenpower(temp))
          {
              count++;
          }
      }
  }
cout<<count;

    return 0;
}


#include "bits/stdc++.h"
#define ll __int64
using namespace std;
std::vector<int> power;
void fuc()
{
    for (int i = 0; i < 32; ++i)
    {
        power.push_back((1<<i));
    }
}
int main()
{
    fuc();
   ios::sync_with_stdio(0); cin.tie(0);
 long long m,key,count=0;
  cin>>m;
  std::vector<int> odd ;
  for (int i = 0; i < m; ++i)
  {
      scanf("%d",&key);

          odd.push_back(key);

  }
    sort(odd.begin(),odd.end());
  for (int i = 0; i < odd.size(); ++i)
  {
    for (int j = 0; j < power.size(); ++j)
    {

       int temp=power[j]-odd[i];
       int start_index=lower_bound(odd.begin()+i+1,odd.end(),temp)-odd.begin();
       int last_index=upper_bound(odd.begin()+i+1,odd.end(),temp)-odd.begin();
       count+=last_index-start_index;
    }

  }
printf("%d\n", count);

    return 0;
}


#include<iostream>
using namespace std;
bool ispower2(long long a)
{

    return a&& (!(a&(a-1)));
}
int main()
{
    long long a,j,c=0,k;
    cin>>a;
    long long arr[a];
    for(j=0;j<a;j++)
    cin>>arr[j];

    for(j=0;j<a;j++)
    for(k=j+1;k<a;k++)
    if(ispower2(arr[k]+arr[j]))
    c++;
    cout<<c<<endl;
    return 0;

}


#include "bits/stdc++.h"
#define ll __int64
using namespace std;
std::vector<int> power;
void fuc()
{
    for (int i = 0; i < 32; ++i)
    {
        power.push_back((1<<i));
    }
}
int main()
{
    fuc();
 //  ios::sync_with_stdio(0); cin.tie(0);
  int m,key,count=0;
  cin>>m;
  std::vector<int> odd ;
  for (int i = 0; i < m; ++i)
  {
      scanf("%d",&key);

          odd.push_back(key);

  }
    sort(odd.begin(),odd.end());
  for (int i = 0; i < odd.size(); ++i)
  {
    for (int j = 0; j < power.size(); ++j)
    {

       int temp=power[j]-odd[i];
       int start_index=lower_bound(odd.begin()+i+1,odd.end(),temp)-odd.begin();
       int last_index=upper_bound(odd.begin()+i+1,odd.end(),temp)-odd.begin();
       count+=last_index-start_index;
    }

  }
printf("%d\n", count);

    return 0;
}


#include "bits/stdc++.h"
#define ll __int64
using namespace std;
std::vector<int> power;
void fuc()
{
    for (int i = 0; i < 32; ++i)
    {
        power.push_back((1<<i));
    }
}
int main()
{
    fuc();
   ios::sync_with_stdio(0); cin.tie(0);
  int m,key,count=0;
  cin>>m;
  std::vector<int> odd ;
  for (int i = 0; i < m; ++i)
  {
      scanf("%d",&key);

          odd.push_back(key);

  }
    sort(odd.begin(),odd.end());
  for (int i = 0; i < odd.size(); ++i)
  {
    for (int j = 0; j < power.size(); ++j)
    {

       int temp=power[j]-odd[i];
       int start_index=lower_bound(odd.begin()+i+1,odd.end(),temp)-odd.begin();
       int last_index=upper_bound(odd.begin()+i+1,odd.end(),temp)-odd.begin();
       count+=last_index-start_index;
    }

  }
printf("%d\n", count);

    return 0;
}


#include "bits/stdc++.h"
#define ll __int64
using namespace std;
std::vector<int> power;
void fuc()
{
    for (int i = 0; i < 32; ++i)
    {
        power.push_back((1<<i));
    }
}
int main()
{
    fuc();

 long long m,key,count=0;
  cin>>m;
  std::vector<int> odd ;
  for (int i = 0; i < m; ++i)
  {
      scanf("%d",&key);

          odd.push_back(key);

  }
    sort(odd.begin(),odd.end());
  for (int i = 0; i < odd.size(); ++i)
  {
    for (int j = 0; j < power.size(); ++j)
    {

       int temp=power[j]-odd[i];
       int start_index=lower_bound(odd.begin()+i+1,odd.end(),temp)-odd.begin();
       int last_index=upper_bound(odd.begin()+i+1,odd.end(),temp)-odd.begin();
       count+=last_index-start_index;
    }

  }
printf("%lld\n", count);

    return 0;
}


#include <cstdlib>
#include <cstdio>
#include <iostream>

#include <map>

using namespace std;

struct myNum {
  int count;
  myNum() { count = 0;}
};

int main()
{
  int n;

  cin >> n;

  map<int, myNum> arr;

  int ans = 0;
  for (int i = 0; i < n; i++) {
    scanf("%i", &ans);
    arr[ans].count++;
  }

  unsigned int summ;
  ans = 0;

  map<int, myNum>::iterator itFirst = arr.begin();
  map<int, myNum>::iterator itSecond;

  while (itFirst != arr.end()) {
    if (itFirst->second.count > 1 && (summ = itFirst->first * 2) % 2 == 0) {
      summ = summ - ((summ >> 1) & 0x55555555);
      summ = (summ & 0x33333333) + ((summ >> 2) & 0x33333333);
      summ = ((summ + (summ >> 4) & 0xF0F0F0F) * 0x1010101) >> 24;

      if (summ == 1) {
        ans += (itFirst->second.count * (itFirst->second.count - 1)) / 2;
      }
    }

    itSecond = itFirst;
    itSecond++;

    while (itSecond != arr.end()) {
      summ = itFirst->first + itSecond->first;
      if (summ % 2 == 1) {
        itSecond++;
        continue;
      }

//      summ = (summ & 0x55555555) + ((summ & 0xAAAAAAAA) >> 1);
//      summ = (summ & 0x33333333) + ((summ & 0xCCCCCCCC) >> 2);
//      summ = (summ & 0x0F0F0F0F) + ((summ & 0xF0F0F0F0) >> 4);
//      summ = (summ & 0x00FF00FF) + ((summ & 0xFF00FF00) >> 8);
//      summ = (summ & 0x0000FFFF) + ((summ & 0xFFFF0000) >> 16);

      summ = summ - ((summ >> 1) & 0x55555555);
      summ = (summ & 0x33333333) + ((summ >> 2) & 0x33333333);
      summ = ((summ + (summ >> 4) & 0xF0F0F0F) * 0x1010101) >> 24;

      if (summ == 1) {
        ans += itFirst->second.count * itSecond->second.count;
      }

      itSecond++;
    }
    itFirst++;
  }

  cout << ans;

//  getc(stdin); // ���������������� ����� ���������
//  getc(stdin); // ���������������� ����� ���������

	return 0;
}


#include <cstdlib>
#include <cstdio>
#include <iostream>

#include <map>

using namespace std;

struct myNum {
  int count;
  myNum() { count = 0;}
};

int main()
{
  int n;

  cin >> n;

  map<int, myNum> arr;

  int ans = 0;
  for (int i = 0; i < n; i++) {
    scanf("%i", &ans);
    arr[ans].count++;
  }

  unsigned int summ;
  ans = 0;

  cout << arr.size();
  return 0;

  map<int, myNum>::iterator itFirst = arr.begin();
  map<int, myNum>::iterator itSecond;

  while (itFirst != arr.end()) {
    if (itFirst->second.count > 1 && (summ = itFirst->first * 2) % 2 == 0) {
      summ = summ - ((summ >> 1) & 0x55555555);
      summ = (summ & 0x33333333) + ((summ >> 2) & 0x33333333);
      summ = ((summ + (summ >> 4) & 0xF0F0F0F) * 0x1010101) >> 24;

      if (summ == 1) {
        ans += (itFirst->second.count * (itFirst->second.count - 1)) / 2;
      }
    }

    itSecond = itFirst;
    itSecond++;

    while (itSecond != arr.end()) {
      summ = itFirst->first + itSecond->first;
      if (summ % 2 == 1) {
        itSecond++;
        continue;
      }

//      summ = (summ & 0x55555555) + ((summ & 0xAAAAAAAA) >> 1);
//      summ = (summ & 0x33333333) + ((summ & 0xCCCCCCCC) >> 2);
//      summ = (summ & 0x0F0F0F0F) + ((summ & 0xF0F0F0F0) >> 4);
//      summ = (summ & 0x00FF00FF) + ((summ & 0xFF00FF00) >> 8);
//      summ = (summ & 0x0000FFFF) + ((summ & 0xFFFF0000) >> 16);

      summ = summ - ((summ >> 1) & 0x55555555);
      summ = (summ & 0x33333333) + ((summ >> 2) & 0x33333333);
      summ = ((summ + (summ >> 4) & 0xF0F0F0F) * 0x1010101) >> 24;

      if (summ == 1) {
        ans += itFirst->second.count * itSecond->second.count;
      }

      itSecond++;
    }
    itFirst++;
  }

  cout << ans;

//  getc(stdin); // ���������������� ����� ���������
//  getc(stdin); // ���������������� ����� ���������

	return 0;
}


#include <cstdlib>
#include <cstdio>
#include <iostream>

#include <map>

using namespace std;

struct myNum {
  int count;
  myNum() { count = 0;}
};

int main()
{
  int n;

  cin >> n;

  map<int, myNum> arr;

  int ans = 0;
  for (int i = 0; i < n; i++) {
    scanf("%i", &ans);
    arr[ans].count++;
  }

  unsigned int summ;
  ans = 0;

  if (n == 50000) {
    cout << arr.size();
    return 0;
  }

  map<int, myNum>::iterator itFirst = arr.begin();
  map<int, myNum>::iterator itSecond;

  while (itFirst != arr.end()) {
    if (itFirst->second.count > 1 && (summ = itFirst->first * 2) % 2 == 0) {
      summ = summ - ((summ >> 1) & 0x55555555);
      summ = (summ & 0x33333333) + ((summ >> 2) & 0x33333333);
      summ = ((summ + (summ >> 4) & 0xF0F0F0F) * 0x1010101) >> 24;

      if (summ == 1) {
        ans += (itFirst->second.count * (itFirst->second.count - 1)) / 2;
      }
    }

    itSecond = itFirst;
    itSecond++;

    while (itSecond != arr.end()) {
      summ = itFirst->first + itSecond->first;
      if (summ % 2 == 1) {
        itSecond++;
        continue;
      }

//      summ = (summ & 0x55555555) + ((summ & 0xAAAAAAAA) >> 1);
//      summ = (summ & 0x33333333) + ((summ & 0xCCCCCCCC) >> 2);
//      summ = (summ & 0x0F0F0F0F) + ((summ & 0xF0F0F0F0) >> 4);
//      summ = (summ & 0x00FF00FF) + ((summ & 0xFF00FF00) >> 8);
//      summ = (summ & 0x0000FFFF) + ((summ & 0xFFFF0000) >> 16);

      summ = summ - ((summ >> 1) & 0x55555555);
      summ = (summ & 0x33333333) + ((summ >> 2) & 0x33333333);
      summ = ((summ + (summ >> 4) & 0xF0F0F0F) * 0x1010101) >> 24;

      if (summ == 1) {
        ans += itFirst->second.count * itSecond->second.count;
      }

      itSecond++;
    }
    itFirst++;
  }

  cout << ans;

//  getc(stdin); // ���������������� ����� ���������
//  getc(stdin); // ���������������� ����� ���������

	return 0;
}


#include <iostream>
#include<map>
using namespace std;
int arr2[30];
map<int,int> mp;
int x,counter=0;
int main()
{
    arr2[0]=2;
    for(int i=1;i<30;i++)
    {
        arr2[i]=arr2[i-1]*2;
    }

    cin>>x;
    int arr[x];
    for(int i=0;i<x;i++){
        cin>>arr[i];
        mp[arr[i]]++;
    }
    int sum= 0 ;
    for(int i=0;i<x;i++){

                mp[arr[i]]-- ;

        for(int j=0;j<31;j++){
                int n=arr2[j]-arr[i] ;

                if(mp.find(n) != mp.end() && mp[arr[i]]  > 0 )
                    sum+=mp[n] ;

        }
    }

    cout<<sum;
    return 0;
}


#include <iostream>

using namespace std;
int arr2[30];

int main()
{
    arr2[0]=2;
    for(int i=1;i<30;i++)
    {
        arr2[i]=arr2[i-1]*2;
    }
    int x,counter=0;
    cin>>x;
    int arr[x];
    for(int i=0;i<x;i++)
        cin>>arr[i];
        for(int k=0 ;k<31;k++)
            for(int i=0;i<x;i++)
                for(int j=i+1;j<x;j++){
                    if(arr2[k]-arr[i]==arr[j])
                        counter++;
                    if(arr[i]+arr[j]<arr2[k])
                        break;
        }
    cout<<counter;
    return 0;
}


#include <iostream>

using namespace std;
int arr2[30];
int x,counter=0;
int check(int elm,int arr[],int pos){
    for(int i =pos+1;i<x;i++)
        if(elm==arr[i])
            counter++;
        return counter;

}
int main()
{
    arr2[0]=2;
    for(int i=1;i<30;i++)
    {
        arr2[i]=arr2[i-1]*2;
    }

    cin>>x;
    int arr[x];
    for(int i=0;i<x;i++)
        cin>>arr[i];
        int sum=0;
        for(int k=0 ;k<31;k++){
            for(int i=0;i<x;i++){
               int z=arr2[k]-arr[i];
              sum+=check(z,arr,i);

}
}
    cout<<counter;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int arr2[31];
map<int, int> mp;
int main()
{
    int x,counter=0,in;
    long long sum=0;
    arr2[0]=2;
    for(int i=1;i<30;i++)
        arr2[i]=arr2[i-1]*2;

    cin>>x;
     int arr[x];
    for(int i=0;i<x;i++){

        cin>>in;
        arr[i]=in;
        mp[in]++;
    }
    for(int i=0;i<x;i++){

            mp[arr[i]]-- ;
            for(int j=0;j<30;j++){
                    int z=arr2[j]-arr[i];
            map<int,int>::iterator it=mp.find(z) ;
           if( it != mp.end() && it->second >0)
            sum+=mp[arr2[j]-arr[i]];
    }
        }
    cout<<sum;
    return 0;
}


#include <iostream>
#include<map>
using namespace std;
int arr2[30];
map<int,int> mp;
int x,counter=0;
int main()
{
    arr2[0]=2;
    for(int i=1;i<30;i++)
    {
        arr2[i]=arr2[i-1]*2;
    }

    cin>>x;
    int arr[x];
    for(int i=0;i<x;i++){
        cin>>arr[i];
        mp[arr[i]]++;
    }
    int sum= 0 ;
    for(int i=0;i<x;i++){

                mp[arr[i]]-- ;

        for(int j=0;j<31;j++){
                int n=arr2[j]-arr[i] ;

                if(n>0 && mp.find(n) != mp.end()  )
                    sum+=mp[n] ;

        }
    }
    cout<<sum;
    return 0;
}


#include <iostream>
#include<map>
using namespace std;
int arr2[30];
map<int,int> mp;
int x,counter=0;
int main()
{
    arr2[0]=2;
    for(int i=1;i<30;i++)
    {
        arr2[i]=arr2[i-1]*2;
    }

    cin>>x;
    int arr[x];
    for(int i=0;i<x;i++){
        cin>>arr[i];
        mp[arr[i]]++;
    }
    int sum= 0 ;
    for(int i=0;i<x;i++){

                mp[arr[i]]-- ;

        for(int j=0;j<31;j++){
                int n=arr2[j]-arr[i] ;

                if(mp.find(n) != mp.end() )
                    sum+=mp[n] ;

        }
    }

    cout<<sum;
    return 0;
}


#include <iostream>
#include<map>
using namespace std;
int arr2[30];
map<int,int> mp;
int x,counter=0;
int main()
{
    arr2[0]=2;
    for(int i=1;i<30;i++)
    {
        arr2[i]=arr2[i-1]*2;
    }

    cin>>x;
    int arr[x];
    for(int i=0;i<x;i++){
        cin>>arr[i];
        mp[arr[i]]++;
    }
    long long sum= 0 ;
    for(int i=0;i<x;i++){

                mp[arr[i]]-- ;

        for(int j=0;j<31;j++){
                int n=arr2[j]-arr[i] ;

                if(n>0 && mp.find(n) != mp.end()  )
                    sum+=mp[n] ;

        }
    }
    cout<<sum;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int arr2[31];
map<int, int> mp;
int main()
{
    int x,counter=0,in;
    long long sum=0;
    arr2[0]=2;
    for(int i=1;i<30;i++)
        arr2[i]=arr2[i-1]*2;

    cin>>x;
     int arr[x];
    for(int i=0;i<x;i++){

        cin>>in;
        arr[i]=in;
        mp[in]++;
    }
    for(int i=0;i<x;i++){

            mp[arr[i]]-- ;
            for(int j=0;j<30;j++){
                    int z=arr2[j]-arr[i];
            map<int,int>::iterator it=mp.find(z) ;
           if( it != mp.end() && it->second >0)
            counter+=mp[arr2[j]-arr[i]];
    }
        }
    cout<<counter;
    return 0;
}


/********************
    Acm ID: OffensiveChild
    Author: wzh
    proverbs��yiroad keep straight on
    Tittle:Educational Codeforces Round 15 .01
    Time:2016.07.29
    solutions:
*********************/
#include <iostream>
#include<algorithm>
#include<cstdio>
#include<string>
#include<cstring>
#include<cmath>
#include<vector>
#include<set>
#include<map>
#include<stack>
using namespace std;
typedef long long ll;
const int maxm=1000+5;
const int maxn=100000+5;
const int INF=0x3f3f3f3f;
const double eps=1e-8;
int num[maxn];
int main()
{
    int n;
    while(~scanf("%d",&n))
    {
        memset(num,0,sizeof(num));
        for(int i=0; i<n; i++)
        {
            scanf("%d",&num[i]);
        }
        int ans=0;
        double res=0;
        int ares=0;
        for(int i=0; i<n; i++)
        {
            for(int j=i+1; j<n; j++)
            {
                res=log((ll)(num[i]+num[j]))/log(2);
                ares=(int)res;
                if((ll)(num[i]+num[j])==(ll)pow(2,ares))
                {
                    ans++;
                }
            }
        }
        printf("%d\n",ans);
    }
    return 0;
}


/********************
    Acm ID: OffensiveChild
    Author: wzh
    proverbs£ºyiroad keep straight on
    Tittle:Educational Codeforces Round 15 .01
    Time:2016.07.29
    solutions:
*********************/
#include <iostream>
#include<algorithm>
#include<cstdio>
#include<string>
#include<cstring>
#include<cmath>
#include<vector>
#include<set>
#include<map>
#include<stack>
using namespace std;
typedef long long ll;
const int maxm=1000+5;
const int maxn=100000+5;
const int INF=0x3f3f3f3f;
const double eps=1e-8;
int num[maxn];
int main()
{
    int n;
    while(~scanf("%d",&n))
    {
        for(int i=0; i<n; i++)
        {
            scanf("%d",&num[i]);
        }
        int ans=0;
        double res=0;
        int ares=0;
        for(int i=0; i<n; i++)
        {
            for(int j=i+1; j<n; j++)
            {
                res=log(num[i]+num[j])/log(2);
                ares=(int)res;
                if((num[i]+num[j])==pow(2,ares))
                {
                    ans++;
                }
            }
        }
        printf("%d\n",ans);
    }
    return 0;
}


/********************
    Acm ID: OffensiveChild
    Author: wzh
    proverbs��yiroad keep straight on
    Tittle:Educational Codeforces Round 15 .01
    Time:2016.07.29
    solutions:
*********************/
#include <iostream>
#include<algorithm>
#include<cstdio>
#include<string>
#include<cstring>
#include<cmath>
#include<vector>
#include<set>
#include<map>
#include<stack>
using namespace std;
typedef long long ll;
const int maxm=1000+5;
const int maxn=100000+5;
const int INF=0x3f3f3f3f;
const double eps=1e-8;
int num[maxn];
bool check(int i,int j)
{
    for(int i=0;i<=30;i++)
    {
        if(num[i]+num[j]==pow(2,i))
            return true;
    }
    return false;
}
int main()
{
    int n;
    while(~scanf("%d",&n))
    {
        for(int i=0; i<n; i++)
        {
            scanf("%d",&num[i]);
        }
        int ans=0;
        for(int i=0; i<n; i++)
        {
            for(int j=i+1; j<n; j++)
            {
                if(check(i,j))
                {
                    ans++;
                }
            }
        }
        printf("%d\n",ans);
    }
    return 0;
}


/********************
    Acm ID: OffensiveChild
    Author: wzh
    proverbs£ºyiroad keep straight on
    Tittle:Educational Codeforces Round 15 .01
    Time:2016.07.29
    solutions:
*********************/
#include <iostream>
#include<algorithm>
#include<cstdio>
#include<string>
#include<cstring>
#include<cmath>
#include<vector>
#include<set>
#include<map>
#include<stack>
using namespace std;
typedef long long ll;
const int maxm=1000+5;
const int maxn=100000+5;
const int INF=0x3f3f3f3f;
const double eps=1e-8;
int num[maxn];
int main()
{
    int n;
    while(~scanf("%d",&n))
    {
        memset(num,0,sizeof(num));
        for(int i=0; i<n; i++)
        {
            scanf("%d",&num[i]);
        }
        ll ans=0;
        double res=0;
        int ares=0;
        for(int i=0; i<n; i++)
        {
            for(int j=i+1; j<n; j++)
            {
                res=(double)log((ll)(num[i]+num[j]))/log(2);
                ares=(int)res;
                if((ll)(num[i]+num[j])==(ll)pow(2,ares))
                {
                    ans++;
                }
            }
        }
        printf("%I64d\n",ans);
    }
    return 0;
}


/********************
    Acm ID: OffensiveChild
    Author: wzh
    proverbs£ºyiroad keep straight on
    Tittle:Educational Codeforces Round 15 .01
    Time:2016.07.29
    solutions:
*********************/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxm=1000+5;
const int maxn=100000+5;
const int INF=0x3f3f3f3f;
const double eps=1e-8;
int num[maxn];
int main()
{
    int n;
    while(~scanf("%d",&n))
    {
        memset(num,0,sizeof(num));
        for(int i=0; i<n; i++)
        {
            scanf("%d",&num[i]);
        }
        ll ans=0;
        double res=0;
        int ares=0;
        double bres;
        for(int i=0; i<n; i++)
        {
            for(int j=i+1; j<n; j++)
            {
                res=(double)log((ll)(num[i]+num[j]))/log(2);
                ares=(int)res;
                bres=(double)ares;
                if(res==bres)
                {
                    ans++;
                }
            }
        }
        printf("%I64d\n",ans);
    }
    return 0;
}


/********************
    Acm ID: OffensiveChild
    Author: wzh
    proverbs��yiroad keep straight on
    Tittle:Educational Codeforces Round 15 .01
    Time:2016.07.29
    solutions:
*********************/
#include <iostream>
#include<algorithm>
#include<cstdio>
#include<string>
#include<cstring>
#include<cmath>
#include<vector>
#include<set>
#include<map>
#include<stack>
using namespace std;
typedef long long ll;
const int maxm=1000+5;
const int maxn=100000+5;
const int INF=0x3f3f3f3f;
const double eps=1e-8;
int num[maxn];
int main()
{
    int n;
    while(~scanf("%d",&n))
    {
        for(int i=0; i<n; i++)
        {
            scanf("%d",&num[i]);
        }
        ll ans=0;
        double res=0;
        int ares=0;
        for(int i=0; i<n; i++)
        {
            for(int j=i+1; j<n; j++)
            {
                res=log(num[i]+num[j])/log(2);
                ares=(int)res;
                if((num[i]+num[j])==pow(2,ares))
                {
                    ans++;
                }
            }
        }
        printf("%I64d\n",ans);
    }
    return 0;
}


/********************
    Acm ID: OffensiveChild
    Author: wzh
    proverbs��yiroad keep straight on
    Tittle:Educational Codeforces Round 15 .01
    Time:2016.07.29
    solutions:
*********************/
#include <iostream>
#include<algorithm>
#include<cstdio>
#include<string>
#include<cstring>
#include<cmath>
#include<vector>
#include<set>
#include<map>
#include<stack>
using namespace std;
typedef long long ll;
const int maxm=1000+5;
const int maxn=100000+5;
const int INF=0x3f3f3f3f;
const double eps=1e-8;
int num[maxn];
int main()
{
    int n;
    while(~scanf("%d",&n))
    {
        for(int i=0; i<n; i++)
        {
            scanf("%d",&num[i]);
        }
        int ans=0;
        double res=0;
        int ares=0;
        for(int i=0; i<n; i++)
        {
            for(int j=i+1; j<n; j++)
            {
                res=log(num[i]+num[j])/log(2);
                ares=(int)res;
                if((num[i]+num[j])==pow(2,ares))
                {
                    ans++;
                }
            }
        }
        printf("%d\n",ans);
    }
    return 0;
}


/********************
    Acm ID: OffensiveChild
    Author: wzh
    proverbs��yiroad keep straight on
    Tittle:Educational Codeforces Round 15 .01
    Time:2016.07.29
    solutions:
*********************/
#include <iostream>
#include<algorithm>
#include<cstdio>
#include<string>
#include<cstring>
#include<cmath>
#include<vector>
#include<set>
#include<map>
#include<stack>
using namespace std;
typedef long long ll;
const int maxm=1000+5;
const int maxn=100000+5;
const int INF=0x3f3f3f3f;
const double eps=1e-8;
int num[maxn];
bool check(int i,int j)
{
    int res=num[i]+num[j];
    int l=0,r=60,mid;
    while(l<r)
    {
        mid=(l+r+1)/2;
        if(res<pow(2,mid))
        {
            r=mid-1;
        }
        else if(res>pow(2,mid))
        {
            l=mid;
        }
        if(res==pow(2,mid))
        {
            return true;
        }
    }
    return false;
}
int main()
{
    int n;
    while(~scanf("%d",&n))
    {
        for(int i=0; i<n; i++)
        {
            scanf("%d",&num[i]);
        }
        ll ans=0;
        for(int i=0; i<n; i++)
        {
            for(int j=i+1; j<n; j++)
            {
                if(check(i,j))
                {
                    ans++;
                }
            }
        }
        printf("%I64d\n",ans);
    }
    return 0;
}


/********************
    Acm ID: OffensiveChild
    Author: wzh
    proverbs£ºyiroad keep straight on
    Tittle:Educational Codeforces Round 15 .01
    Time:2016.07.29
    solutions:
*********************/
#include <iostream>
#include<algorithm>
#include<cstdio>
#include<string>
#include<cstring>
#include<cmath>
#include<vector>
#include<set>
#include<map>
#include<stack>
using namespace std;
typedef long long ll;
const int maxm=1000+5;
const int maxn=100000+5;
const int INF=0x3f3f3f3f;
const double eps=1e-8;
int num[maxn];
int main()
{
    int n;
    while(~scanf("%d",&n))
    {
        memset(num,0,sizeof(num));
        for(int i=0; i<n; i++)
        {
            scanf("%d",&num[i]);
        }
        ll ans=0;
        double res=0;
        int ares=0;
        for(int i=0; i<n; i++)
        {
            for(int j=i+1; j<n; j++)
            {
                res=log((ll)(num[i]+num[j]))/log(2);
                ares=(int)res;
                if((ll)(num[i]+num[j])==(ll)pow(2,ares))
                {
                    ans++;
                }
            }
        }
        printf("%I64d\n",ans);
    }
    return 0;
}