Harryxun/stf_run huggingface dataset:
class Graph:
    edges = {}

    def append_edge(self, sv, ev, weight = 1):
        if sv in self.edges:
            self.edges[sv].append((ev, weight))
        else:
            self.edges[sv] = [(ev, weight)]

    def bfs(self, sv):
        dist = [0]*len(self.edges.keys())
        q = []   # キュー
        q.append(sv)
        dist[sv] = 0
        connect_vtxs = []
        while len(q) > 0:
            p = q.pop(0)     # キュー取りだし（先頭）
            connect_vtxs.append(p)
            for (ev, w) in self.edges[p]:
                if dist[ev] != -1:
                    continue
                q.append(ev)    # キュー追加
                dist[ev] = dist[p] + 1
        return dist, connect_vtxs


N, X, Y = list(map(int, input().split()))

g = Graph()
for i in range(N - 1):
    g.append_edge(i, i + 1)
    g.append_edge(i + 1, i)
g.append_edge(X - 1, Y - 1)
g.append_edge(Y - 1, X - 1)

dist_cnt = [0]*N
for sv in range(N):
    dist, connect_vtxs = g.bfs(sv)
    for j in range(dist.shape[0]):
        if dist[j] == -1: continue
        dist_cnt[dist[j]] += 1

for i in range(N-1):
    print(int(dist_cnt[i+1]/2))


### FIXED CODE ###

K, N = list(map(int, input().split()))
A = list(map(int, input().split()))
A.append(K+A[0])
diff_list = []
for i in range(len(A) - 1):
    diff_list.append(A[i+1]-A[i])
print(K - max(diff_list))
n, m = map(int, input().split())
cards = list(map(int, input().split()))
 
def calc():
  for i in range(m):
    b,c = map(int, input().split())
    if(min(cards) > c or b == 0):
      continue
    for i in range(b):
      if(b == 0):
        break
      card_min = min(cards)
      if(c > card_min and b > 0):
        cards.remove(card_min)
        cards.append(c)
        b -= 1
  return sum(cards)
 
print(calc())

### FIXED CODE ###

a,b = map(int, input().split())
if(a >= 13):
  print(b)
elif(a >= 6):
  print(int(b/2))
else:
  print(0)
import math
​
A, B = list(map(int,input().split()))
​
cnt = 0
for i in range(1,10000):
    X = math.floor(i * 0.08)
    Y = math.floor(i * 0.1)
    if A == X and B == Y:
        print(i)
        cnt += 1
        break
​
if cnt == 0:
    print(-1)


### FIXED CODE ###

import math

A, B = list(map(int,input().split()))

cnt = 0
for i in range(1,100000):
    X = math.floor(i * 0.08)
    Y = math.floor(i * 0.1)
    if A == X and B == Y:
        print(i)
        cnt += 1
        break
        
if cnt == 0:
    print(-1)
# -*- coding: utf-8 -*-
"""
Created on Sun Mar  3 19:52:57 2019

@author: Yamazaki Kenichi
"""
import sys
sys.setrecursionlimit(3000)

N,M = map(int,input().split())
bb = [list(map(int,(input().split()))) for i in range(M)]

def comb2(N):
    return N*(N-1)//2
ans = [int(comb2(N))]
A = [-1 for i in range(N+1)]
B = [[] for i in range(N+1)]
T=[[-1,-1,-1] for i in range(N+1)]
def p(u):
    return T[u][0]
def ch(u):
    return T[u][1]
def root(u):
    if p(u) == -1:
        return u
    else:
        return root(p(u))
def leef(u):
    if ch(u) == -1:
        return u
    else:
        return leef(ch(u))
def pn(u):
    if p(u) == -1:
        return 0
    else:
        return pn(p(u))+1
def cn(u):
    if ch(u) == -1:
        return 0
    else:
        return cn(ch(u)) +1
def al(u):
    return T[u][2]
k = 0
bb.reverse()
for c in bb:
    if ans[-1] == 0:
        ans.append(0)
        continue
    if al(c[0]) == -1 and al(c[1]) ==-1:
        T[c[0]][2],T[c[1]][2] = 1,1
        T[c[0]][1] = c[1]
        T[c[1]][0] = c[0]
        ans.append(ans[-1]-1)
    elif al(c[0]) != -1 and al(c[1]) ==-1:
        T[c[1]][2] = 1
        res = pn(c[0])+1+cn(c[0])
        tmp = leef(c[0])
        T[tmp][1] = c[1]
        T[c[1]][0] = tmp
        ans.append(ans[-1]-res)
    elif al(c[0]) == -1 and al(c[1]) !=-1:
        T[c[0]][2] = 1
        res = pn(c[1])+1+cn(c[1])
        tmp = leef(c[1])
        T[tmp][1] = c[0]
        T[c[0]][0] = tmp
        ans.append(ans[-1]-res)
    elif root(c[0]) != root(c[1]):
        res = (pn(c[0])+1+cn(c[0])) * (pn(c[1])+1+cn(c[1]))
        tmp = leef(c[0])
        tmp2 = root(c[1])
        T[tmp][1] = tmp2
        T[tmp2][0] = tmp
        ans.append(ans[-1]-res)
    else:
        ans.append(ans[-1])
        continue
#    print(pn(c[0]),cn(c[0]),pn(c[1]),cn(c[1]))
#    print(T)
for i in range(M):
    print(ans[-i-2])

### FIXED CODE ###

# -*- coding: utf-8 -*-
"""
Created on Wed Mar  6 14:59:59 2019

@author: Yamazaki Kenichi
"""

N,M = map(int,input().split())
bb = [list(map(int,(input().split()))) for i in range(M)]

def comb2(N):
    return N*(N-1)//2
ans = [int(comb2(N))]
bb.reverse()

T = [[-1,1] for i in range(N+1)]
def p(u):
    return T[u][0]
def findset(u):
    if p(u) == -1:
        return u
    else:
        T[u][0] = findset(p(u))
        return T[u][0]
def unite(u,v):
    if findset(u) == findset(v):
        return    
    if T[findset(u)][1] >= T[findset(v)][1]:
        T[findset(u)][1] += T[findset(v)][1]
        T[findset(v)][0] = findset(u)
    else:
        T[findset(v)][1] += T[findset(u)][1]
        T[findset(u)][0] = findset(v)
        
for c in bb:
    if findset(c[0]) != findset(c[1]):
        res1 = T[findset(c[0])][1]
        res2 = T[findset(c[1])][1]
        unite(c[0],c[1])
        ans.append(ans[-1]-res1*res2)
    else:
        ans.append(ans[-1])
for i in range(M):
    print(ans[-i-2])
A = list(map(int, input().split(' ')))

def multi_all(A):
  s = 1
  for a in A:
    s *= a
  return s

M = multi_all(A)

if N == 1: print(A[0])
else:
  S = 0
  for a in A:
    S += M / a
  print(M/S)


### FIXED CODE ###

N = int(input())
A = list(map(int, input().split(' ')))

def multi_all(A):
  s = 1
  for a in A:
    s *= a
  return s

M = multi_all(A)

if N == 1: print(A[0])
else:
  S = 0
  for a in A:
    S += M / a
  print(M/S)
n, m = [int(x) for x in input().split()]
food_list = [0 for x in range(m)]

for i in range(n):
  s = [int(x) for x in input().split()]
  k = s[0]
  e = s[1:]
  for j in range(k):
    food_list[e[j]-1] += 1

ans = 0
for i in range(m):
  if food_list[i] == n:
    ans += 1
print(ans)

### FIXED CODE ###

a, b = [int(x) for x in input().split()]

if b%a == 0:
  print(a+b)
else:
  print(b-a)
a=int(input())
b=int(input())
c=int(input())
d=int(input())
e=int(input())

x=[a,b,c,d,e]

l10=[int(i) for i in x if i % 10==0]
res=x
for n in l10:
    res.remove(n)

if not len(l10)==5:
    min_d=9
    for i in res:
        if int(str(i)[-1])<min_d:
            min_d=int(str(i)[-1])
            min_num=i
    
    re2=res
    
    re2.remove(min_num)
    
    s=0
    for si in re2:
        if len(str(si))==2:
            s+=int(str(si)[0])*10+10
        elif len(str(si))==1:
            s+=10
        else:
            s+=int(str(si)[:-1])*10+10 
    print(sum(l10)+min_num+s)
else:
    print(sum(l10))
    
    

    


### FIXED CODE ###

a=int(input())
b=int(input())
c=int(input())
d=int(input())
e=int(input())

x=[a,b,c,d,e]

l10=[int(i) for i in x if i % 10==0]
res=x
for n in l10:
    res.remove(n)

if not len(l10)==5:
    min_d=9
    for i in res:
        if int(str(i)[-1])<=min_d:
            min_d=int(str(i)[-1])
            min_num=i
    
    re2=res
    
    re2.remove(min_num)
    
    s=0
    for si in re2:
        if len(str(si))==2:
            s+=int(str(si)[0])*10+10
        elif len(str(si))==1:
            s+=10
        else:
            s+=int(str(si)[:-1])*10+10 
    print(sum(l10)+min_num+s)
else:
    print(sum(l10))
N = int(input())
A = input()
A = A.split()
B =[]
C = []
ans1 = 0
ans2 = 0
for i in range(N):
    B.append(int(A[i]))
    C.append(int(A[i]))
C.sort(reverse=True)
Max = C[0]
b = Max - N
for i in range(N):
    ans1 = ans + abs(B[i]-(i+b+1))
for i in range(N):
    ans2 = ans + abs(B[i]-(i+1))
if ans1>ans2:
    ans = ans1
else:
    ans = ans2

print(ans)

### FIXED CODE ###

import math
N = int(input())
A = input()
A = A.split()
B =[]
C = []
ans1 = 0
ans2 = 0
for i in range(N):
    B.append(int(A[i]))
    C.append(int(A[i])-i)
C.sort(reverse=True)

n = math.floor(N/2)
b = C[n]
b1 = C[n-1]

for i in range(N):
    ans1 = ans1 + abs(B[i]-(i+b))
for i in range(N):
    ans2 = ans2 + abs(B[i]-(i+b1))
ans = min(ans1, ans2)
print(ans)
import numpy as np
H,W,M=map(int,input().split())

B=np.zeros((H,W))
for i in range(M):
    inp=list(map(int,input().split()))
    B[inp[0]-1][inp[1]-1]=1
BT=B.T
maxmax=0
for i in range(H):
    for j in range(W):
        sumsum=0
        sumsum=np.sum(B[i])+np.sum(BT[j])-B[i][j]
        #print((np.sum(B[i]),np.sum(BT[j]),B[i][j]))
        if maxmax<sumsum:
            maxmax=sumsum
print(int(maxmax))

### FIXED CODE ###

N,X,T=map(int,input().split())

if N%X==0:
    print(str(((N//X))*T))
else:
    print(str(((N//X)+1)*T))
a,b,c,x=map(int,input().split())
i=0
for s in range(1,a+1):
    for t in range(1,b+1):
         for r in range(1,c+1):
            if 500*s+100*t+50*r==x:
                i+=1
print(i)

### FIXED CODE ###

a,b,c,x=[int(input()) for i in range(4)]
i=0
for _ in range(a+1):
    for j in range(b+1):
        for k in range(c+1):
            if 500*_+100*j+50*k==x:
                i+=1
print(i)
a = list(map(int, input().split()))
if a.count(5)==2 and a.count(7)=1:
    print("Yes")
else:
    print("No")

### FIXED CODE ###

a = list(map(int, input().split()))
b = a.count(5)
c = a.count(7)
if b==2 and c==1:
  print("YES")
else:
  print("NO")
import numpy as np
N=int(input())
H=np.array(list(map(int,input().split())))
diffH = np.diff(H)
if np.any((diffH[range(N-1)] + diffH[range(1, N)]) <= -2):
  print("No")
 
print("Yes")

### FIXED CODE ###

import numpy as np
N = int(input())
H = list(map(int, input().split()))

max = 0
for i in range(N):
  if max < H[i]:
    max = H[i]
  if max - H[i] >= 2:
    print("No")
    exit(0)
print("Yes")
n=int(input())
s=input()
count=0
count2=0
d=[]
hk3=0
hk2=0
hk1=0
for j in range(100,1000):
  k3=j//100
  k2=(j-k3*100)//10
  k1=j-k3*100-k2*10
  for i in range(n):
    if str(k3)==s[i]:
      hk3=1
    if str(k2)==s[i] and hk3==1:
      hk2=1
    if str(k1)==s[i] and hk2==1:
      hk1=1
    if hk1==1 and hk2==1 and hk3==1:
      d.append(j)
  hk1=0
  hk2=0
  hk3=0
for j in range(1,10):
  for i in range(n):
    if s[i]=="0":
      count=1
    if count==1 and s[i]=="0":
      count2=1
    if count2=0 and s[i]==str(j):
      d.append(j)
  count=0
  count2=0
for j in range(10,100):
  k2=j//10
  k1=j-k2*10
  for i in range(n):
    if s[i]=="0":
      count=1
    if str(k2)==s[i] and count=1:
      hk2=1
    if str(k1)==s[i] and hk2==1 and count=1:
      hk1=1
    if hk1==1 and hk2==1:
      d.append(j)
  count=0
  hk1=0
  hk2=0
print(len(set(d)))
      

### FIXED CODE ###

n=int(input())
x=input()
ans=0
for i in range(0,10):
  k=0
  ss="00"+str(i)
  for j in x:
    if k<3 and j==ss[k]:
      k+=1
  if k==3:
    ans+=1
for i in range(10,100):
  k=0
  ss="0"+str(i)
  for j in x:
    if k<3 and j==ss[k]:
      k+=1
  if k==3:
    ans+=1
for i in range(100,1000):
  k=0
  ss=str(i)
  for j in x:
    if k<3 and j==ss[k]:
      k+=1
  if k==3:
    ans+=1
print(ans)
S = str(input())
Q = int(input())

qs = [input().split() for i in range(Q)]

i = 0
while i < len(qs):
    q = qs[i]
    if q[0] == '1':
        if qs[i+1][0] == '1':
            i += 2
        else:
            S = S[::-1]
            i += 1
    else:
        if q[1] == '1':
            S = q[2] + S
        else:
            S = S + q[2]
        i += 1



print(S)

### FIXED CODE ###

from collections import deque

S = str(input())
Q = int(input())

d = deque([S[i] for i in range(len(S))])
#print(d)

flg = 0

for i in range(Q):
    query = input()
    if query[0] == '1':
        flg = flg%2 + 1
    else:
        t, f, c = query.split()
        if f == '1':
            if flg % 2 == 0:
                d.appendleft(c)
            else:
                d.append(c)
        else:
            if flg % 2 == 0:
                d.append(c)
            else:
                d.appendleft(c)
if flg % 2 == 0:
    print(''.join(list(d)))
else:
    tmp = ''.join(list(d))
    print(tmp[::-1])
n, x = map(int, input().split())
xi = list(map(int, input().split()))

import fraction
import functools

def gcd(*numbers):
    return functools.reduce(fraction.gcd, numbers)

xi = map(lambda y:y-x, xi)
print(gcd(*xi))

### FIXED CODE ###

n, x = map(int, input().split())
xi = list(map(int, input().split()))

def gcd(a, b):
	while b:
		a, b = b, a % b
	return a

def gcd_l(*numbers):
	ret = numbers[0]
	for n in numbers[1:]:
		ret = gcd(ret, n)
	return ret

xi = map(lambda y:abs(y-x), xi)
print(gcd_l(*xi))
#初期入力
import sys
N,M = (int(x) for x in input().split())
if M==0:
    if N==1:
        print(0)
    elif N==2:
        print(10)
    elif N==3:
        print(100)
    sys.exit(0)
digit ={str(i):[] for i in range(1,N+1)}

for i in range(M):
    d,n =input().split()
    digit[d].append(n)

ans =""
for i,v in digit.items():
    if i =="1" and v[0] =="0" and (len(v) ==2 or len(v) ==3): #1桁目（一番左）は✖０、最小値「１」
            print(-1)
            sys.exit(0)
    elif len(v) ==2:
        if v[0] !=v[1]: #同じ桁なのに違う値は✖
            print(-1)
            sys.exit(0)
        else:
            ans +=v[0]
    elif len(v) ==3:
        if v[0] !=v[1] or v[2] !=v[1] or v[0] !=v[2]:
            print(-1)
            sys.exit(0)
        else:
            ans +=v[0]
    elif len(v) ==1:
        ans +=v[0]
    elif len(v) ==0:
        if i =="1":
            ans +="1" #1桁目（一番左）は✖０、最小値「１」
        else:
            ans +="0"

print(ans)

### FIXED CODE ###


from collections import defaultdict
N,M = (int(x) for x in input().split())
keta_num_str = [ (input().split()) for i in range(M) ]

#各桁をキー、数字を値の辞書にする
suuji = ""
num_str_dic = defaultdict(set)
kotae_dic ={ str(i):"0" for i in range(1,N +1) } #　各桁に初期値”０”を入力。一番右（１の位）は入力がなければ無し
if 1< N:
    kotae_dic["1"] = "1" # 2桁以上の時は左の桁は最低１
for i in keta_num_str:   
    num_str_dic[i[0]].add(i[1])


for i,v in num_str_dic.items():
    if 1 < len(v) : # 一つの桁に複数の値がある時はエラー
        kotae_dic ={}
        break
    
    else:
        kotae_dic[i] = list(v)[0]

# 表示
import math
if kotae_dic == {}: # 一つの桁に複数の値の時        
    print(-1)
else:
    kotae_dic_sorted = sorted(kotae_dic.items(),key=lambda x:int(x[0]))
    kotae_str = "".join( [i[1] for i in kotae_dic_sorted ] ) # 辞書の値を連結
    kotae_int =int(kotae_str)
    if kotae_int == 0 and 1< N: # "00"などはエラー、"0"はOK
        print(-1)
    elif kotae_int == 0 and N == 1:
        print("0")
    elif 10**(N-1) > kotae_int or kotae_int >= 10** N: # 桁があってない＝一番左の桁が”０”はエラー
        print(-1)
    elif kotae_dic["1"] == "0" and 1 < N: 
        kotae_dic["1"] ="1"
    elif 1000 <= kotae_int: # 答えが１０００以上はエラー
        print(-1)

    else:
        print(kotae_int)
n,m = map(int,input().split())

s = [0]*(n+1)
for i in range(m):
    s[int(input())] = 1

mod = (10**9)+7
ans = 0

def steps(now):
    if now == n:
        global ans
        ans += 1
        ans %= mod
    else:
        if s[now+1] == 0:
            steps(now+1)
        if now+2 <= n:
            if s[now+2] == 0:
                steps(now+2)
            
steps(0)
print(ans)

### FIXED CODE ###

n,m = map(int,input().split())

ng = [0]*(n+1)
for i in range(m):
    ng[int(input())] = 1

mod = (10**9)+7
dp = [0]*(n+1)
dp[0] = 1

for i in range(1,n+1):
    if ng[i] == 1:
        dp[i] = 0
        continue
    if i == 1:
        dp[1] = 1
        continue
    dp[i] = (dp[i-2] + dp[i-1])%mod

print(dp[n])
import numpy as np

# input
N = int(input().split())
sequence = list( map(int, input().split()) )

# a_N>N must be removed
remove = np.sum(sequence>N)
sequence = sequence[sequence<=N]

index = np.unique(sequence)

for idx in index(sequence):

    n_idx = np.sum(sequence==idx)
    if n_idx < idx:
        remove += n_idx
    else:
        remove += (n_idx-idx)

print(remove)

### FIXED CODE ###

import numpy as np

# input
N = int(input().split()[0])
sequence = np.array(list( map(int, input().split()) ))

# a_N>N must be removed
remove = np.sum(sequence>N)
sequence = sequence[sequence<=N]

index = np.unique(sequence)

for idx in index:

    n_idx = np.sum(sequence==idx)
    if n_idx < idx:
        remove += n_idx
    else:
        remove += (n_idx-idx)

print(remove)
a = list(input())
su = 0
s = 0
k = 0
for i in a:
  s += int(i)
a.reverse()
for i in a:
  su += i*pow(10,k)
  k += 1
  
if su % s == 0:
  print("Yes")
else:
  print("No")

### FIXED CODE ###

a = list(input())
su = 0
s = 0
k = 0
for i in a:
  s += int(i)
a.reverse()
for i in a:
  su += int(i)*pow(10,k)
  k += 1
  
if su % s == 0:
  print("Yes")
else:
  print("No")
import sys
     
    args = list(map(int, input().split()))
         
    if (args[0] < args[1] and args[1] < args[2]) or (args[2] < args[1] and args[1] < args[0]):
        print("Yes")
    else:
        print("No")

### FIXED CODE ###

import sys
         
args = list(map(int, input().split()))
             
if (args[0] < args[2] and args[2] < args[1]) or (args[1] < args[2] and args[2] < args[0]):
    print("Yes")
else:
    print("No")
def solve():
    S = input()
    K = int(input())
    a = min(list(S))
    lis = set()
    if len(S)>=5:
        for i,s in enumerate(S):
            if s==a:
                for j in range(i+1,min(len(S)+1,i+K+1)):
                    lis.add(S[i:j])
    else:
        for i in range(len(S)):
            for j in range(i+1,len(S)+1):
                lis.add(S[i:j])
    ans = sorted(list(lis))[K-1]
    return ans
print(solve())

### FIXED CODE ###

def solve():
    S = input()
    K = int(input())
    strlist = sorted(list(S))
    lis = set()
    p = 0
    while len(list(lis))<K:
        a = strlist[p]
        if len(S)>=5:
            for i,s in enumerate(S):
                if s==a:
                    for j in range(i+1,min(len(S)+1,i+K+1)):
                        lis.add(S[i:j])
        else:
            for i in range(len(S)):
                for j in range(i+1,len(S)+1):
                    lis.add(S[i:j])
        p += 1
    ans = sorted(list(lis))[K-1]
    return ans
print(solve())
mylist = []
x = 0
while x <= 1:
  val = input()
  x = x + 1
  if val:
    mylist.append(val)
  else:
    break
 


a = mylist[0].split( )
A = int(a[0])
B = int(a[1])
C = int(a[2])
K = int(mylist[1])
r = A
g = B 
b = C



for k in range(K):
    if r > b and r > g:
        if r > b:
            b = b * 2
        elif r > g:
            g = g * 2
        elif g > b:
            b = b * 2
    elif g > r:
        g = g * 2
    elif b == g or b == r:
        b = b * 2
    elif b > g and g == r
        g = g * 2


if b > g and g > r:
    print("yes")
else:
    print("no")    


### FIXED CODE ###

import sys

x = input()
y = int(x)


a = 400
b = 0
kyu = 8

while(1):
    
    if a + b <= y <= a + b + 199:
        print(str(kyu))
        break
    
    b = b + 200
    kyu = kyu - 1
class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n+1)

    def sum(self, i):  # sum in [0, i)
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s

    def add(self, i, x):  # i > 0
        assert i > 0
        while i <= self.size:
            self.tree[i] += x
            i += i & -i


N, Q = map(int, input().split())
c = list(map(int, input().split()))

lr = []
for i in range(Q):
    l, r = map(int, input().split())
    lr.append([l-1, r-1, i])

lr.sort(key=lambda x: x[1])

rightest = [-1] * N
rightest_pos = set()

current_q = 0

bit = Bit(N)

ans = [0] * Q

for i in range(N):
    if rightest[c[i]] != -1:
        rightest_pos.remove(rightest[c[i]])
        bit.add(rightest[c[i]]+1, -1)
    rightest[c[i]] = i
    rightest_pos.add(i)
    bit.add(i+1, 1)

    while current_q < Q and lr[current_q][1] == i:
        ans[lr[current_q][2]] = bit.sum(lr[current_q][1] + 1) - bit.sum(lr[current_q][0])
        current_q += 1

for i in range(Q):
    print(ans[i])


### FIXED CODE ###

class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n+1)

    def sum(self, i):  # sum in [0, i)
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s

    def add(self, i, x):  # i > 0
        assert i > 0
        while i <= self.size:
            self.tree[i] += x
            i += i & -i


N, Q = map(int, input().split())
c = list(map(int, input().split()))

lr = []
for i in range(Q):
    l, r = map(int, input().split())
    lr.append([l-1, r-1, i])

lr.sort(key=lambda x: x[1])

rightest = [-1] * (N + 1)
current_q = 0
bit = Bit(N)
ans = [0] * Q

for i in range(N):
    if rightest[c[i]] != -1:
        bit.add(rightest[c[i]]+1, -1)
    rightest[c[i]] = i
    bit.add(i+1, 1)

    while current_q < Q and lr[current_q][1] == i:
        ans[lr[current_q][2]] = bit.sum(lr[current_q][1] + 1) - bit.sum(lr[current_q][0])
        current_q += 1

for i in range(Q):
    print(ans[i])
a, b, c, d = map(int, input().split())

if a+b > c+d:
    print('Left')

elif a+b = c+d:
    print('Balanced')

else:
    print('Right')

### FIXED CODE ###

a, b, c, d = map(int, input().split())

if a+b > c+d:
    print('Left')

elif a+b == c+d:
    print('Balanced')

else:
    print('Right')
n, k = [int(e) for e in input().split()]
h = [int(e) for e in input().split()]
cost = [0] * n
for i in range(1, n):
  cost[i] = cost[j] + min(abs(h[i] - h[j]) for j in range(max(0, i - k), i))
print(cost[n - 1])


### FIXED CODE ###

n, k = [int(e) for e in input().split()]
h = [int(e) for e in input().split()]
cost = [0] * n
cost[1] = abs(h[1] - h[0])
for i in range(1, n):
  cost[i] = min(abs(h[i] - h[j]) + cost[j] for j in range(max(0, i - k), i))
print(cost[n - 1])
a,b,k=map(int, input().split())
if k>b:
    k=b-1

l=[i for i in range(a,b+1)] 
set_l=set()
for i in range(k):
    set_l.add(l[i])
for i in range(b-a-k+1,b-a+1):
    set_l.add(l[i])

l_set = list(set_l)
l_set.sort()
for i in range(len(l_set)):
    print(l_set[i])

### FIXED CODE ###

a,b,k=map(int,input().split())

ans=list(range(a,min(a+k,b)))+list(range(max(a,b-k+1),b+1))
ans=set(ans)
ans=list(ans)
ans.sort()
for i in range(len(ans)):
    print(ans[i])
div = ["dream", "dreamer", "erase", "eraser"]
rev = []
t = ""
s_rev = s[::-1]
for d in div:
    rev.append(d[::-1])

result = True
i = 0
while i < len(s):
    can_divide = False
    for d in rev:
        if len(s_rev) - i >= len(d) and s_rev[i:i + len(d)] == d:
            can_divide = True
            i += len(d)
    if not can_divide:
        result = False
        break

print("YES" if result else "NO")


### FIXED CODE ###

s = input()
t = ""
while len(t) < len(s):
    target_len = len(s) - len(t)

    if s[len(t)] == 'd':
        if target_len == 5:
            t += "dream"
        elif target_len == 7:
            t += "dreamer"
        elif target_len > 7:
            if s[len(t) + 5] != 'd' and s[len(t) + 5:len(t) + 7 + 1] != "era":
                t += "dreamer"
            else:
                t += "dream"
        else:
            break
    else:
        if target_len == 5:
            t += "erase"
        elif target_len == 6:
            t += "eraser"
        elif target_len > 6:
            if s[len(t) + 5] != 'd' and s[len(t) + 5:len(t) + 6 + 2] != "era":
                t += "eraser"
            else:
                t += "erase"
        else:
            break

    if s[0:len(t)] != t:
        break

print("YES" if s == t else "NO")
N, Y = map(int, input().split())

for x in range(N+1):
  for y in range(N+1-x):
    for z in range(N+1-y):
        if x*10000 + y*5000 + z*1000 == Y:
           print(x, y, z)
       else:
           print(-1,-1,-1)


### FIXED CODE ###

N, Y = map(int, input().split())
 
for x in range(N+1):
  for y in range(N+1-x):
        if x*10000 + y*5000 + (N-x-y)*1000 == Y:
           print(x, y, N-x-y)
           exit()
 
print("-1 -1 -1")
X, Y = map(int, input().split())
 
ans = 'No'
if a in range(X + 1):
    b = X - a
    if 2 * a + 4 * b == Y:
        ans = 'Yes'
print(ans)

### FIXED CODE ###

X, Y = map(int, input().split())
 
ans = 'No'
for a in range(X + 1):
    b = X - a
    if 2 * a + 4 * b == Y:
        ans = 'Yes'
print(ans)