301980: CF376A. Lever

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Lever

题意翻译

你有一根杠杆,用一个字符串s表示($3≤|s|≤10^{6}$)。 若字符串的下标为i的字符为“^”,则表示杠杆的支点的坐标为i; 若字符串的下标为i的字符为“=”,则表示坐标为i的位置没有任何东西; 若字符串的下标为i的字符为一个数字c($1≤c≤9$),则表示在坐标为i处,有一个质量为c的重物挂在杠杆上。 杠杆一开始是平衡的,杠杆自重忽略不计。 你的任务是判断这根杠杆的状态(平衡、向左倾斜或向右倾斜)。 注意,本题需要使用64位整型。 输入格式 一行,一个字符串s。 保证字符串中只包含一个“^”,保证杠杆的支点不位于杠杆的任何一端。 输出格式 若杠杆平衡,则输出“balance”; 若杠杆向左倾斜,则输出“left”; 若杠杆向右倾斜,则输出“right”。

题目描述

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.

输入输出格式

输入格式


The first line contains the lever description as a non-empty string $ s $ $ (3<=|s|<=10^{6}) $ , consisting of digits (1-9) and characters "^" and "=". It is guaranteed that the line contains exactly one character "^". It is guaranteed that the pivot of the lever isn't located in any end of the lever bar. To solve the problem you may need 64-bit integer numbers. Please, do not forget to use them in your programs.

输出格式


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: ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF376A/0359e72dda22a274eb38d88d30b1bd1ec9bb42a2.png) ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF376A/38b3b4f3b6b93773b325339c4e16a40e36fc023b.png) ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF376A/1ab4793a8a931653a79d269916fc7bb4acbb492c.png) ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF376A/afcccb56029eeba60149120d1e1e0d28d9d34c18.png)

Input

题意翻译

你有一根杠杆,用一个字符串s表示($3≤|s|≤10^{6}$)。 若字符串的下标为i的字符为“^”,则表示杠杆的支点的坐标为i; 若字符串的下标为i的字符为“=”,则表示坐标为i的位置没有任何东西; 若字符串的下标为i的字符为一个数字c($1≤c≤9$),则表示在坐标为i处,有一个质量为c的重物挂在杠杆上。 杠杆一开始是平衡的,杠杆自重忽略不计。 你的任务是判断这根杠杆的状态(平衡、向左倾斜或向右倾斜)。 注意,本题需要使用64位整型。 输入格式 一行,一个字符串s。 保证字符串中只包含一个“^”,保证杠杆的支点不位于杠杆的任何一端。 输出格式 若杠杆平衡,则输出“balance”; 若杠杆向左倾斜,则输出“left”; 若杠杆向右倾斜,则输出“right”。

加入题单

算法标签: