TnT/CodeNet4Repair huggingface dataset:
Problem:
There are N empty boxes arranged in a row from left to right. The integer i is written on the i-th box from the left (1 \leq i \leq N).  For each of these boxes, Snuke can choose either to put a ball in it or to put nothing in it.  We say a set of choices to put a ball or not in the boxes is good when the following condition is satisfied:    * For every integer i between 1 and N (inclusive), the total number of balls contained in the boxes with multiples of i written on them is congruent to a_i modulo 2.  Does there exist a good set of choices? If the answer is yes, find one good set of choices.

Incorrect submission (verdict: Wrong Answer):
N = int(input())
a = list(int(x) for x in input().split())
b = [0] * N

index = N // 2

for i in range(index,N):
    b[i] = a[i]

count = 0

for i in range(index):

    for j in range(index-i-1+(index-i),N,index-i):
        count += a[j]

    if count % 2 != a[i]:
        b[i] = 1

    count = 0

for i in range(N):
    if b[i] == 1:
        count += 1

print(count)

for i in range(N):
    print(b[i],end=' ')

print()

        


Fixed, accepted submission:
N = int(input())
arr = list(int(x) for x in input().split())
flag = [-1] * N
ans = []


for i in range(N-1,-1,-1):
    
    sum = 0

    
    for j in range(i,N,i+1):
        
        if j == i:
            continue
        else:
            if flag[j] == 1:
                sum += 1

    
    if sum % 2 == arr[i]:
        flag[i] = 0
    else:
        flag[i] = 1
        
        
        ans.append(i+1)


num = len(ans)

if num == 0:
    print(num)
else:
    print(num)
    print(*ans)
Problem:
Write a program which identifies the number of combinations of three integers which satisfy the following conditions:    * You should select three distinct integers from 1 to n.   * A total sum of the three integers is x.  For example, there are two combinations for n = 5 and x = 9.    * 1 + 3 + 5 = 9   * 2 + 3 + 4 = 9

Incorrect submission (verdict: Wrong Answer):
#!usr/bin/env python3

import sys


def subset_sum(numbers, target, partial=[]):
    s = sum(partial)

    if s == target:
        if len(partial) != 3:
            return None
        print(*partial)

    if s >= target:
        return None

    for i in range(len(numbers)):
        n = numbers[i]
        remaining = numbers[i+1:]
        if len(partial) == 3:
            break
        subset_sum(remaining, target, partial + [n])


def program_runner():
    while True:
        lst = [int(num) for num in sys.stdin.readline().split()]
        if lst[0] == lst[1] == 0:
            break
        num_list = [num for num in range(1, lst[0]+1)]
        subset_sum(num_list, lst[1])


def main():
    program_runner()


if __name__ == '__main__':
    main()

Fixed, accepted submission:
#!/usr/local/env python3

import sys


def main():
    while True:
        count = 0
        n, r = map(int, sys.stdin.readline().split())
        if n == r == 0:
            break
        for n1 in range(1, n-1):
            for n2 in range(n1+1, n):
                for n3 in range(n2+1, n+1):
                    if n1 + n2 + n3 == r:
                        count += 1
        print(count)


if __name__ == '__main__':
    main()
Problem:
You are given a grid of squares with H horizontal rows and W vertical columns, where each square is painted white or black. HW characters from A_{11} to A_{HW} represent the colors of the squares. A_{ij} is `#` if the square at the i-th row from the top and the j-th column from the left is black, and A_{ij} is `.` if that square is white.  We will repeatedly perform the following operation until all the squares are black:    * Every white square that shares a side with a black square, becomes black.  Find the number of operations that will be performed. The initial grid has at least one black square.

Incorrect submission (verdict: Wrong Answer):
from collections import deque

H,W=map(int, input().split())
S=[]
S.append(list(['X']*(W+2)))
for h in range(H):
    S.append(['X']+list(input())+['X'])
S.append(list(['X']*(W+2)))

q=deque([])
d=[(1,0),(-1,0),(0,1),(0,-1)]
cnt_n=0
def add_q(S):
    for h in range(1,H+1):
        for w in range(1,W+1):
            if S[h][w]=='#':
                for dy,dx in d:
                    q.append([h+dy,w+dx])
    return S,q

def chnge_are(S,q):
    while q:
        y,x = q.popleft()
        S[y][x]='#'
    return S
        
def res_chk(S,cnt_n):
    res=0
    for h in range(H+2):
        if S[h].count('.')!=0:
            res=1
    if res==1:
        cnt_n+=1
        S,q=add_q(S)
        S=chnge_are(S,q)
        return res_chk(S,cnt_n)
    else:
        return cnt_n

res_chk(S,cnt_n)

Fixed, accepted submission:
from scipy.ndimage import distance_transform_cdt
H,W=map(int, input().split())
S=list(list(input()) for h in range(H))
for h in range(H):
    for w in range(W):
        if S[h][w]=="#":
            S[h][w]=0
        else:
            S[h][w]=1

print(distance_transform_cdt(S, metric='taxicab').max())
Problem:
We will buy a product for N yen (the currency of Japan) at a shop.  If we use only 1000-yen bills to pay the price, how much change will we receive?  Assume we use the minimum number of bills required.

Incorrect submission (verdict: Wrong Answer):
import math
n=int(input())
total = math.ceil(n/1000)
print(total-n)

Fixed, accepted submission:
import math
n=int(input())
total = math.ceil(n/1000)

print((total)*1000-n)
Problem:
You have an integer variable x. Initially, x=0.  Some person gave you a string S of length N, and using the string you performed the following operation N times. In the i-th operation, you incremented the value of x by 1 if S_i=`I`, and decremented the value of x by 1 if S_i=`D`.  Find the maximum value taken by x during the operations (including before the first operation, and after the last operation).

Incorrect submission (verdict: Wrong Answer):
n = int(input())
x=0
s=input()
ans=0
for i in range(n):
    if s[i]=="I":
        x=x+1
    else:
        x=x-1
    ans=max(ans,x)
print(x)

Fixed, accepted submission:
n = int(input())
x=0
s=input()
ans=0
for i in range(n):
    if s[i]=="I":
        x=x+1
    else:
        x=x-1
    ans=max(ans,x)
print(ans)
Problem:
Snuke has a favorite restaurant.  The price of any meal served at the restaurant is 800 yen (the currency of Japan), and each time a customer orders 15 meals, the restaurant pays 200 yen back to the customer.  So far, Snuke has ordered N meals at the restaurant. Let the amount of money Snuke has paid to the restaurant be x yen, and let the amount of money the restaurant has paid back to Snuke be y yen. Find x-y.

Incorrect submission (verdict: Wrong Answer):
n = int(input())
print(800*n - 200 * n// 15)

Fixed, accepted submission:
n = int(input())
print(800*n - 200 * (n// 15))
Problem:
How many multiples of d are there among the integers between L and R (inclusive)?

Incorrect submission (verdict: Wrong Answer):
l, r, d = [int(x) for x in input().split()]
count = 0
for i in range(l, r+1):
  if not l%d:
    count += 1
print(count)


Fixed, accepted submission:
l, r, d = [int(x) for x in input().split()]
count = 0
for i in range(l, r+1):
  if not i%d:
    count += 1
print(count)
Problem:
You are given an integer N. Find the number of the positive divisors of N!, modulo 10^9+7.

Incorrect submission (verdict: Wrong Answer):
N = int(input())
mod = 10**9+7
arr = [1 for i in range(N+1)]
for i in range(2,N+1):
    if arr[i] > 0:
        j = 2*i
        while(j<N+1):
            arr[j] = 0
            j += i
prime = []
for i in range(2,N):
    if arr[i] != 0:
        prime.append(i)
count = 1
for n in prime:
    tmp = n
    i = 0
    while(tmp < N+1):
        i += N//tmp
        tmp *= n
    count *= (i+1)
print(count%mod)

Fixed, accepted submission:
N = int(input())
mod = 10**9+7
arr = [1 for i in range(N+1)]
for i in range(2,N+1):
    if arr[i] > 0:
        j = 2*i
        while(j<N+1):
            arr[j] = 0
            j += i
prime = []
for i in range(2,N+1):
    if arr[i] != 0:
        prime.append(i)
count = 1
for n in prime:
    tmp = n
    i = 0
    while(tmp < N+1):
        i += N//tmp
        tmp *= n
    count *= (i+1)
print(count%mod)
Problem:
For an integer n not less than 0, let us define f(n) as follows:    * f(n) = 1 (if n < 2)   * f(n) = n f(n-2) (if n \geq 2)  Given is an integer N. Find the number of trailing zeros in the decimal notation of f(N).

Incorrect submission (verdict: Wrong Answer):
N = int(input())
# c = 0
# while True:
#     a = N // 5
#     b = N % 5
#     if b != 0:
#         N = b
#     else:
#         N = a
#     c += N
#     if N < 5:
#         break

# print(int(c / 2))

n = 1
ans = 0
while 5 ** n < N:
    a = (N // (5 ** n))
    b = (N % (10 ** n))
    if b == 0:
        a = int(a / 2)
    ans += a
    n += 1
print(ans)


Fixed, accepted submission:
import math
N = int(input())

def main(N):
    if N % 2 == 1:
        print(0)
        return
    n = 1
    ans = 0
    N //= 2
    while N:
        N //= 5
        ans += N
    print(ans)

if __name__ == "__main__":
    main(N)
Problem:
Print all the integers that satisfies the following in ascending order:    * Among the integers between A and B (inclusive), it is either within the K smallest integers or within the K largest integers.

Incorrect submission (verdict: Wrong Answer):
a,b,k=map(int,input().split())
L=set([i for i in range(a,min(a+k,b))]+[i for i in range(max(b-k+1,a),b+1)])
for a in L:
    print(a)

Fixed, accepted submission:
a,b,k=map(int,input().split())
R=range(a,b+1)
for x in sorted(set(R[:k])|set(R[-k:])):
    print(x)
Problem:
Snuke has N sticks. The length of the i-th stick is l_i.  Snuke is making a snake toy by joining K of the sticks together.  The length of the toy is represented by the sum of the individual sticks that compose it. Find the maximum possible length of the toy.

Incorrect submission (verdict: Wrong Answer):
n,k = map(int, input().split())
listA = list(map(int, input().split()))
listA.sort()
listB = listA[:k]
sum(listB)


Fixed, accepted submission:
n,k = map(int, input().split())
listA = list(map(int, input().split()))
listA.sort(reverse=True)
listB = listA[:k]
print(sum(listB))
Problem:
AtCoder Mart sells 1000000 of each of the six items below:    * Riceballs, priced at 100 yen (the currency of Japan) each   * Sandwiches, priced at 101 yen each   * Cookies, priced at 102 yen each   * Cakes, priced at 103 yen each   * Candies, priced at 104 yen each   * Computers, priced at 105 yen each  Takahashi wants to buy some of them that cost exactly X yen in total. Determine whether this is possible.   (Ignore consumption tax.)

Incorrect submission (verdict: Wrong Answer):
n = int(input().strip())
valid = { 0: True }
for i in range(1, n+1):
  valid[i] = any(valid.get(i-j, False) for j in range(100, 106))
print (valid[n])

Fixed, accepted submission:
n = int(input().strip())
valid = { 0: True }
for i in range(1, n+1):
  valid[i] = any(valid.get(i-j, False) for j in range(100, 106))
print (1 if valid[i] else 0)
Problem:
There are N positive integers written on a blackboard: A_1, ..., A_N.  Snuke can perform the following operation when all integers on the blackboard are even:    * Replace each integer X on the blackboard by X divided by 2.  Find the maximum possible number of operations that Snuke can perform.

Incorrect submission (verdict: Wrong Answer):
a = list(map(int, input().split()))
count = 0
flag = 1

while flag == 1:
    b = list(map(lambda x: x % 2, a))
    if b.count(1) == 0:
        a = list(map(lambda x: x / 2, a))
        count += 1
    else:
        flag = 0

print(count)

Fixed, accepted submission:
n = int(input())
a = list(map(int, input().split()))
cnt = 0
flag = True

while flag:
    ans = []
    for i in a:
        if i % 2 == 1:
            flag = False
        else:
            ans.append(i/2)
    if len(ans) == n:
        cnt += 1
        a = ans

print(cnt)
Problem:
There is a cave.  The cave has N rooms and M passages. The rooms are numbered 1 to N, and the passages are numbered 1 to M. Passage i connects Room A_i and Room B_i bidirectionally. One can travel between any two rooms by traversing passages. Room 1 is a special room with an entrance from the outside.  It is dark in the cave, so we have decided to place a signpost in each room except Room 1. The signpost in each room will point to one of the rooms directly connected to that room with a passage.  Since it is dangerous in the cave, our objective is to satisfy the condition below for each room except Room 1.    * If you start in that room and repeatedly move to the room indicated by the signpost in the room you are in, you will reach Room 1 after traversing the minimum number of passages possible.  Determine whether there is a way to place signposts satisfying our objective, and print one such way if it exists.

Incorrect submission (verdict: Wrong Answer):
from collections import deque
N, M = map(int, input().split())
G = [[] for i in range(N)]
R = [0]*N
for m in range(M):
    A,B = map(int, input().split())
    G[A-1].append(B-1)
    G[B-1].append(A-1)
d = deque()
for n in G[0]:
    d.append(n)
    R[n]=1
while len(d)>0:
    i = d.popleft()
    for j in range(len(G[i])):
        if R[G[i][j]] == 0 and G[i][j]!=0:
            d.append(G[i][j])
            R[G[i][j]]=i+1

for n in range(1,N):
    print(R[n])

Fixed, accepted submission:
import sys
from collections import deque
N, M = map(int, input().split())
G = [[] for i in range(N)]
R = [0]*N
for m in range(M):
    A,B = map(int, input().split())
    G[A-1].append(B-1)
    G[B-1].append(A-1)
d = deque()
for n in G[0]:
    d.append(n)
    R[n]=1
while len(d)>0:
    i = d.popleft()
    for j in range(len(G[i])):
        if R[G[i][j]] == 0 and G[i][j]!=0:
            d.append(G[i][j])
            R[G[i][j]]=i+1
for n in range(1,N):
    if R[n]==0:
        print("No")
        sys.exit()
print("Yes")
for n in range(1,N):
    print(R[n])
Problem:
Write a program which reads three integers a, b and c, and prints the number of divisors of c between a and b.

Incorrect submission (verdict: Wrong Answer):
(a, b, c) = [int(i) for i in input().split()]
cnt = 0
for i in range(a, b + 1):
    if (c % 1) == 0:
        cnt = cnt + 1
print(cnt)

Fixed, accepted submission:
(a, b, c) = [int(i) for i in input().split()]
cnt = 0
for i in range(a, b + 1):
    if (c % i) == 0:
        cnt = cnt + 1
print(cnt)
Problem:
AtCoDeer the deer has found two positive integers, a and b. Determine whether the concatenation of a and b in this order is a square number.

Incorrect submission (verdict: Wrong Answer):
a,b=map(int,input().split())
if b==100:
  s=a*1000+b
elif b>=10:
  s=a*100+b
else:
  s=a*10+b
j=1
temp=0
while j**2<s:
  if j**2==s:
    print("Yes")
    temp=1
    break
  j=j+1
if temp==0:
  print("No")

Fixed, accepted submission:
a,b=map(int,input().split())
if b==100:
  s=a*1000+b
elif b>=10:
  s=a*100+b
else:
  s=a*10+b
j=1
temp=0
while j**2<=s:
  if j**2==s:
    print("Yes")
    temp=1
    break
  j=j+1
if temp==0:
  print("No")
Problem:
We have a long seat of width X centimeters. There are many people who wants to sit here. A person sitting on the seat will always occupy an interval of length Y centimeters.  We would like to seat as many people as possible, but they are all very shy, and there must be a gap of length at least Z centimeters between two people, and between the end of the seat and a person.  At most how many people can sit on the seat?

Incorrect submission (verdict: Wrong Answer):
x,y,z=map(int,input().split())
print(x//((y+z)+z))

Fixed, accepted submission:
x,y,z=map(int,input().split())
print((x-z) // (y+z))
Problem:
Taro's summer vacation starts tomorrow, and he has decided to make plans for it now.  The vacation consists of N days. For each i (1 \leq i \leq N), Taro will choose one of the following activities and do it on the i-th day:    * A: Swim in the sea. Gain a_i points of happiness.   * B: Catch bugs in the mountains. Gain b_i points of happiness.   * C: Do homework at home. Gain c_i points of happiness.  As Taro gets bored easily, he cannot do the same activities for two or more consecutive days.  Find the maximum possible total points of happiness that Taro gains.

Incorrect submission (verdict: Wrong Answer):
N = int(input())
siawaseList = [list(map(int,input().split())) for _ in range(N)]

dp = [[0]*3]*N


dp[0][0] = siawaseList[0][0]
dp[0][1] = siawaseList[0][1]
dp[0][2] = siawaseList[0][2] 

for i in range(1,N):
    dp[i][0] = max(dp[i-1][1]+siawaseList[i][0],dp[i-1][2]+siawaseList[i][0])
    dp[i][1] = max(dp[i-1][0]+siawaseList[i][1],dp[i-1][2]+siawaseList[i][1])
    dp[i][2] = max(dp[i-1][0]+siawaseList[i][2],dp[i-1][1]+siawaseList[i][2])
print(max(dp[N-1][0],dp[N-1][1],dp[N-1][2]))

Fixed, accepted submission:
N = int(input())
siawaseList = [list(map(int,input().split())) for _ in range(N)]

dp = [[0 for _ in range(3)] for __ in range(N)]


dp[0][0] = siawaseList[0][0]
dp[0][1] = siawaseList[0][1]
dp[0][2] = siawaseList[0][2] 
for i in range(1,N):
    dp[i][0] = max(dp[i-1][1]+siawaseList[i][0],dp[i-1][2]+siawaseList[i][0])
    dp[i][1] = max(dp[i-1][0]+siawaseList[i][1],dp[i-1][2]+siawaseList[i][1])
    dp[i][2] = max(dp[i-1][0]+siawaseList[i][2],dp[i-1][1]+siawaseList[i][2])
print(max(dp[N-1][0],dp[N-1][1],dp[N-1][2]))
Problem:
Snuke has a grid consisting of three squares numbered 1, 2 and 3. In each square, either `0` or `1` is written. The number written in Square i is s_i.  Snuke will place a marble on each square that says `1`. Find the number of squares on which Snuke will place a marble.

Incorrect submission (verdict: Wrong Answer):
if __name__ == '__main__':
    # line = str(input())
    line = '000'
    count = 0
    if line[0] == '1':
        count += 1
    if line[1] == '1':
        count += 1
    if line[2] == '1':
        count += 1
    print(count)


Fixed, accepted submission:
if __name__ == '__main__':
    line = str(input())
    count = 0
    if line[0] == '1':
        count += 1
    if line[1] == '1':
        count += 1
    if line[2] == '1':
        count += 1
    print(count)
Problem:
There is a rectangle in the xy-plane, with its lower left corner at (0, 0) and its upper right corner at (W, H). Each of its sides is parallel to the x-axis or y-axis. Initially, the whole region within the rectangle is painted white.  Snuke plotted N points into the rectangle. The coordinate of the i-th (1 ≦ i ≦ N) point was (x_i, y_i).  Then, he created an integer sequence a of length N, and for each 1 ≦ i ≦ N, he painted some region within the rectangle black, as follows:    * If a_i = 1, he painted the region satisfying x < x_i within the rectangle.   * If a_i = 2, he painted the region satisfying x > x_i within the rectangle.   * If a_i = 3, he painted the region satisfying y < y_i within the rectangle.   * If a_i = 4, he painted the region satisfying y > y_i within the rectangle.  Find the area of the white region within the rectangle after he finished painting.

Incorrect submission (verdict: Wrong Answer):
W, H, N = map(int, input().split())
x_min, x_max, y_min, y_max = 0, H, 0, W 
for i in range(N):
    x, y, a = map(int, input().split())
    if a == 1 and x > x_min:
        x_min = x
    elif a == 2 and x < x_max:
        x_max = x
    elif a == 3 and y > y_min:
        y_min = y
    elif a == 4 and y < y_max:
        y_max = y
if x_max > x_min and y_max > y_min:
    S = (x_max - x_min) * (y_max - y_min)
else:
    S = 0
print(S)

Fixed, accepted submission:
W, H, N = map(int, input().split())
u, U, v, V = 0, W, 0, H
for _ in range(N):
    x, y, a = map(int,input().split())
    if a == 1:
        u = max(u,x)
    if a == 2:
        U = min(U,x)
    if a == 3:
        v = max(v,y)
    if a == 4:
        V = min(V,y)
f = lambda x:x if x > 0 else 0
print(f(U-u)*f(V-v))
Problem:
An elementary school student Takahashi has come to a variety store.  He has two coins, A-yen and B-yen coins (yen is the currency of Japan), and wants to buy a toy that costs C yen. Can he buy it?  Note that he lives in Takahashi Kingdom, and may have coins that do not exist in Japan.

Incorrect submission (verdict: Wrong Answer):
A, B, C = map(int, input().split())

print('Yes' if A+B == C else 'No')

Fixed, accepted submission:
A, B, C = map(int, input().split())

print('Yes' if A+B >= C else 'No')
Problem:
We have a sequence of length N, a = (a_1, a_2, ..., a_N). Each a_i is a positive integer.  Snuke's objective is to permute the element in a so that the following condition is satisfied:    * For each 1 ≤ i ≤ N - 1, the product of a_i and a_{i + 1} is a multiple of 4.  Determine whether Snuke can achieve his objective.

Incorrect submission (verdict: Wrong Answer):
n, *A = map(int, open(0).read().split())

def f(q):
  y = 0
  while True:
    q, r = divmod(q, 2)
    if r == 1:
      break
    y += 1
  return y

B = [0] * 3
for a in A:
  b = f(a)
  B[0] += b == 0
  B[1] += b == 1
  B[2] += b >= 2
print('Yes' if B[0] + B[1]%2 <= B[2] else 'No')

Fixed, accepted submission:
n, *A = map(int, open(0).read().split())

def f(x):
  y = 0
  q, r = divmod(x, 2)
  while r == 0:
    y += 1
    q, r = divmod(q, 2)
  return y

B = [0] * 3
for a in A:
  b = f(a)
  B[0] += b == 0
  B[1] += b == 1
  B[2] += b >= 2
print('Yes' if B[0] + (B[1]!=0) <= B[2]+1 else 'No')
Problem:
In the online judge system, a judge file may include multiple datasets to check whether the submitted program outputs a correct answer for each test case. This task is to practice solving a problem with multiple datasets.  Write a program which reads an integer x and print it as is. Note that multiple datasets are given for this problem.

Incorrect submission (verdict: Wrong Answer):
i = 1
while True:
    x = int(input())
    if (x == 0):
        break
    print(f"Case {i}: {x}")


Fixed, accepted submission:
i = 1
while True:
    x = int(input())
    if (x == 0):
        break
    print(f"Case {i}: {x}")
    i+=1
Problem:
"Pizza At", a fast food chain, offers three kinds of pizza: "A-pizza", "B-pizza" and "AB-pizza". A-pizza and B-pizza are completely different pizzas, and AB-pizza is one half of A-pizza and one half of B-pizza combined together. The prices of one A-pizza, B-pizza and AB-pizza are A yen, B yen and C yen (yen is the currency of Japan), respectively.  Nakahashi needs to prepare X A-pizzas and Y B-pizzas for a party tonight. He can only obtain these pizzas by directly buying A-pizzas and B-pizzas, or buying two AB-pizzas and then rearrange them into one A-pizza and one B-pizza. At least how much money does he need for this? It is fine to have more pizzas than necessary by rearranging pizzas.

Incorrect submission (verdict: Wrong Answer):
A,B,C,X,Y=map(int, input().split())
ans = 500000000
ans = min(ans, A*X+B*Y)
ans = min(ans, C*min(X,Y))
ans = min(ans, (A+B)*min(X,Y)+C*(abs(X-Y)))
print(ans)


Fixed, accepted submission:
A,B,C,X,Y=map(int, input().split())
ans = 50000000000
for i in range( max(X,Y)+1 ):
  ans = min(ans, C*i*2 + A*(max(0,(X-i)))+B*(max(0,(Y-i))))
print(ans)
Problem:
A balance scale tips to the left if L>R, where L is the total weight of the masses on the left pan and R is the total weight of the masses on the right pan. Similarly, it balances if L=R, and tips to the right if L<R.  Takahashi placed a mass of weight A and a mass of weight B on the left pan of a balance scale, and placed a mass of weight C and a mass of weight D on the right pan.  Print `Left` if the balance scale tips to the left; print `Balanced` if it balances; print `Right` if it tips to the right.

Incorrect submission (verdict: Wrong Answer):
A, B, C, D = input().split()

if A + B > C + D:
    print('Left')
elif A + B < C + D:
    print('Right')
else:
    print('Balanced')


Fixed, accepted submission:
I = input().split()
A, B, C, D = [int(i) for i in I]

if A + B > C + D:
    print('Left')
elif A + B < C + D:
    print('Right')
else:
    print('Balanced')