Lever

呵呵~~CF刚做的题,本来还寻思再去CF找这个题用来写博客费事,呵呵。。第二次选拔自己送上门来。题目不难,见代码。

Description

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

The decoding of the lever description is given below.

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

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

Input

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

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

Output

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

Sample Input

Input
=^==
Output
balance
Input
9===^==1
Output
left
Input
2==^7==
Output
right
Input
41^52==
Output
balance
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <stdio.h>
#include <string.h>
char s[10000004];
int main()
{
    long long x, y;
    int k, i, n1, n;
    scanf("%s",s);
    k = strlen(s);
    n1 = 0;
    n = 1;x = 0; y = 0;
    for(i = 0; i < k; i++)
    {
        if(s[i]!='^'&&n!=0)
        n1++;
        else if(s[i]=='^')
        {
            n=0;
        }
    }
    for(i = 0; i < n1; i++)
    {
        if(s[i]=='=')
            s[i] = '0';
        x = x + (s[i]-'0')*(n1-i);
    }
    for(i = n1+1; i < k; i++)
    {
        if(s[i]=='=')
            s[i] = '0';
        y = y + (s[i]-'0')*(i-n1);
    }
    if(x==y)
        printf("balance\n");
    else if(x>y)
        printf("left\n");
    else
        printf("right\n");
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值