CF376A.Lever

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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

The decoding of the lever description is given below.

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

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

输入格式

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

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

输出格式

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

输入输出样例

  • 输入#1

    =^==
    

    输出#1

    balance
    
  • 输入#2

    9===^==1
    

    输出#2

    left
    
  • 输入#3

    2==^7==
    

    输出#3

    right
    
  • 输入#4

    41^52==
    

    输出#4

    balance
    

说明/提示

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

The pictures to the examples:

首页