• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 众包
  • 赞助商
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
HaibaraAi
博客园    首页    新随笔    联系   管理    订阅  订阅

Codeforce Round #221 Div2 A

A. Lever
time limit per test 1 second
memory limit per test 256 megabytes
 

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 test(s)
Input
=^==
Output
balance
Input
9===^==1
Output
left
Input
2==^7==
Output
right
Input
41^52==
Output
balance
Note

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

The pictures to the examples:

 

 

 

 1 #pragma comment(linker,"/STACK:102400000,102400000")
 2 #include <cstdio>
 3 #include <vector>
 4 #include <cmath>
 5 #include <queue>
 6 #include <cstring>
 7 #include <iostream>
 8 #include <algorithm>
 9 using namespace std;
10 #define INF 0x7fffffff
11 #define mod 1000000007
12 #define ll long long
13 #define maxn 1000005
14 #define pi acos(-1.0)
15 int n, m;
16 int t;
17 char s[maxn];
18 int a[maxn];
19 int main(){
20     scanf("%s", s);
21     n = strlen(s);
22     for (int i = 0; i < n; i++){
23         if (s[i] == '^')t = i;
24     }
25     ll a=0, b=0;
26     for (int i = 0; i < n; i++){
27         if (s[i] == '=')continue;
28         if (i < t)a += ((ll)t - (ll)i)*(s[i] - '0');
29         if (i>t)b += ((ll)i - (ll)t)*(s[i] - '0');
30     }
31     if (a == b){ printf("balance\n"); return 0; }
32     if (a < b)printf("right\n");
33     else printf("left\n");
34 }
View Code
posted @ 2013-12-25 12:34  HaibaraAi  阅读(150)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2026
浙公网安备 33010602011771号 浙ICP备2021040463号-3