Harryxun/stf_run huggingface dataset:
import sys

S = input()

while S:
    prefix = S[0:5]
    if prefix == 'dream':
        if S[5:7] == 'er':
            if len(S) >= 8 and S[7] == 'a':
                S = S[5:]
            else:
                S = S[7:]
        else:
            S = S[5:]
    elif prefix == 'erase':
        if len(S) >= 6 and S[5] == 'r':
            S = S[6:]
        else:
            S = S[5:]
    else:
        print('NO')
        sys.exit(0)
    print(S)
print('YES')


### FIXED CODE ###

import sys

S = input()

while S:
    prefix = S[0:5]
    if prefix == 'dream':
        if S[5:7] == 'er':
            if len(S) >= 8 and S[7] == 'a':
                S = S[5:]
            else:
                S = S[7:]
        else:
            S = S[5:]
    elif prefix == 'erase':
        if len(S) >= 6 and S[5] == 'r':
            S = S[6:]
        else:
            S = S[5:]
    else:
        print('NO')
        sys.exit(0)
    # print(S)
print('YES')
s = input()
K = int(input())

s_list = list(set(s))
s_list.sort()

ans = []

def pack_in_dict_order(s_in):
    ans.append(s_in)
    if len(ans)==K:
        pass
    else:
        for s_l in s_list:
            temp = s_in + s_l
            if temp in s:
                pack_in_dict_order(temp)

for s_in in s_list:
    pack_in_dict_order(s_in)

print(ans[K-1])

### FIXED CODE ###

s = input()
K = int(input())

s_list = list(set(s))
s_list.sort()

ans = []

def pack_in_dict_order(s_in):
    ans.append(s_in)
    if len(ans)<K:
        for s_l in s_list:
            temp = s_in + s_l
            if temp in s:
                pack_in_dict_order(temp)

for s_in in s_list:
    pack_in_dict_order(s_in)

print(ans[K-1])
from scipy.special import comb
inf = 10 ** 9 + 7
n, k = map(int, input().split())
for i in range(k):
    print(int(comb(n + 1 - k, i + 1) * comb(k - 1, i) % inf))

### FIXED CODE ###

mod = 10 ** 9 + 7
n, k = map(int, input().split())
red, blue = n-k, k
ai = red + 1
print(ai)
for i in range(2, blue+1):
    ai = ai * (red-i+2) * (blue-i+1) // (i*(i-1))
    print(ai % mod)
n=int(input())
s=list(input())
x=[]
y=[]

for i in range(n):
  if s[i]=='R':
    x+=[i]
  elif s[i]=='W':
    y+=[i]
    
ans=0
if y==[]:
  print(ans)
else:
  while True:
    if x[-1]>y[0]:
      x.pop()
      y.pop(0)
      ans+=1
      continue
    
    else:
      print(ans)
      break

### FIXED CODE ###

n=int(input())
s=list(input())
x=[]
y=[]

for i in range(n):
  if s[i]=='R':
    x+=[i]
  elif s[i]=='W':
    y+=[i]
    
ans=0


while True:
    if len(y)==0:
      print(ans)
      break
    elif len(x)==0:
      print(ans)
      break
    elif x[-1]>y[0]:
      x.pop()
      y.pop(0)
      ans+=1
      continue
    
    else:
      print(ans)
      break
A = list(map(int,input().split()))
if A[3] == 0 or A[3]%2 == 0:
    print(A[0]-A{1])
else:
    print(A[1]-A[0])

### FIXED CODE ###

A = list(map(int,input().split()))
if A[3] == 0:
    print(A[0]-A[1])
elif A[3]%2 == 0:
    print(A[0]-A[1])
else:
    print(A[1]-A[0])
import numpy as np
n, a = [int(i) for i in input().split()]
x = [int(i) for i in input().split()]
sx=sum(x)
dp= np.zeros((n+1,n*a+1),dtype=int)
dp[0][0]=1
ans=0

for k in range(1,n+1):
  for i in range(k,-1,-1):
    for j in range(0, sx * n + 1):
      if j>=x[k-1] and i>=1:
        dp[i][j]= dp[i][j] + dp[i-1][j-x[k-1]]
      else:
        dp[i][j]= dp[i][j] 
      
for i in range(1,n+1):
  ans+=dp[i][a*i]

print(ans)

### FIXED CODE ###

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

dp=[[0 for i in range(a*n+1)] for j in range(n+1)]
dp[0][0]=1
ans=0
f=0

for k in range(1,n+1):
  kx=x[k-1]
  f+=kx
  for i in range(k,0,-1):
    for j in range(kx,a*n+1):
      dp[i][j] += dp[i-1][j-kx]
      if j > f:
        break
      
for i in range(1,n+1):
  ans+=dp[i][a*i]

print(ans)
n=int(input())
s=list(input())
x=0
ans=0
for i in range(n):
  if s[i]=='I':
    x+=1
  else s[i]=='D':
    x-=1
  ans=max(ans,x)
print(ans)

### FIXED CODE ###

n=int(input())
s=list(input())
x=0
ans=0
for i in range(n):
  if s[i]=='I':
    x+=1
  else:
    x-=1
  ans=max(ans,x)
print(ans)
from collections import deque
S=deque(input())
q=int(input())
rev=False
for i in range(q):
  c=list(input().split())
  if c[0]=='1':
    rev=not rev
  elif c[1]=='1' and rev:
    S.appendleft(c[2])
  elif c[1]=='2' and not rev:
    S.appendleft(c[2])
  else:
    S.append(c[2])
if rev:
  S.reverse()
ans=''.join(S)
print(ans)

### FIXED CODE ###

a=input()
if len(set(a))==1:
  print("No")
else:
  print("Yes")
A, B, K = map(int, input().split())
l = list(range(A, B+1))
l = sorted(list(set(l[:K]+l[-K:])))

for v in l:
    print(v)

### FIXED CODE ###

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

if A+K-1 < B-K+1:
    l = list(range(A, A+K))+list(range(B-K+1, B+1))
else:
    l = list(range(A, B+1))

for v in l:
    print(v)
N, K = map(int, input().split())
P = list(map(int, input().split()))
for i in range(N):
    P[i] -= 1
C = list(map(int, input().split()))
 
ans = -(10 ** 18)
 
for si in range(N):
    x = si
    loop = []
    total = 0
    while 1:
        x = P[x]
        loop.append(C[x])
        total += C[x]
        if x == si:
            break
    T = len(loop)  
    tmp = 0
    for i in range(T):
        tmp += loop[i]
        if K < i + 1:
            break
        now = tmp
        if total > 0:  
            loop_times = (K - (i + 1)) // T  
            now += total * loop_times
        ans = max(ans, now)
 
print(ans)
 
N, K = map(int, input().split())
P = list(map(int, input().split()))
for i in range(N):
    P[i] -= 1
C = list(map(int, input().split()))

ans = -(10 ** 18)

for si in range(N):
    x = si
    loop = []
    total = 0
    while 1:
        x = P[x]
        loop.append(C[x])
        total += C[x]
        if x == si:
            break
    T = len(loop) 
    tmp = 0
    for i in range(T):
        tmp += loop[i]
        if K < i + 1:
            break
        now = tmp
        if total > 0: 
            loop_times = (K - (i + 1)) // T 
            now += total * loop_times
        ans = max(ans, now)

print(ans)


### FIXED CODE ###

N, K = map(int, input().split())
P = list(map(int, input().split()))
for i in range(N):
    P[i] -= 1
C = list(map(int, input().split()))
 
ans = -(10 ** 18)
 
for si in range(N):
    x = si
    loop = []
    total = 0
    while 1:
        x = P[x]
        loop.append(C[x])
        total += C[x]
        if x == si:
            break
    T = len(loop)  # 周期の大きさ
    tmp = 0
    for i in range(T):
        tmp += loop[i]
        if K < i + 1:
            break
        now = tmp
        if total > 0:  # loopの和が正ならloopを回した方がお得
            loop_times = (K - (i + 1)) // T  # 何周できるか
            now += total * loop_times
        ans = max(ans, now)
 
print(ans)
from fractions import gcd

N,M = map(int,input().split())
S = input()
T = input()
if len(S) < len(T):
    S,T = T,S

Xlen = N * M // gcd(N, M)
X = [0] * Xlen

for i,s in enumerate(list(S)):
    num = i*(Xlen//N)
    X[num] = s

for i,t in enumerate(list(T)):
    num = i*(Xlen//M)
    if X[num] == 0 or X[num] == t:
        continue
    else:
        print(-1)
        exit()

print(Xlen)


### FIXED CODE ###

from fractions import gcd

N,M = map(int,input().split())
S = input()
T = input()

G = gcd(N, M)
L = N * M // G
ng = N//G
mg = M//G

for i in range(G):
    Nnum = i*ng
    Mnum = i*mg
    if S[Nnum] != T[Mnum]:
        print(-1)
        exit()

print(L)
# coding: utf-8
# Your code here!

N, L = map(int, input().split())
arr = [input() for i in range(N)]
sort_arr = sorted(arr)
for i in range(L):
    print(sort_arr[i], end = "")

### FIXED CODE ###

# coding: utf-8
# Your code here!

N, L = map(int, input().split())
arr = [input() for i in range(N)]
sort_arr = sorted(arr)
for i in range(len(sort_arr)):
    print(sort_arr[i], end = "")
a,b = map(int,input().split())
grid_b = [list('#'*100) for _ in range(50)]
grid_w = [list('.'*100) for _ in range(50)]
for i in range(1, a):
    grid_b[2*(i//10)-1][2*(i%10)-1] = '.'
for i in range(1, b):
    grid_w[2*(i//10)-1][2*(i%10)-1] = '#'
print(100, 100)
grid = grid_b + grid_w
for g in grid:
    print(*g)

### FIXED CODE ###

a,b=map(int,input().split())
ans=[['#' for i in range(100)] for j in range(50)]
ans+=[['.' for i in range(100)] for j in range(50)]
for i in range(a-1):
    ans[(i//50)*2][(i%50)*2]='.'
for i in range(b-1):
    ans[(i//50)*2+52][(i%50)*2]='#'
print(100,100)
for i in range(100):
    print(''.join(ans[i]))
import numpy as np

n, w = map(int, input().split())
li = [list(map(int, input().split())) for _ in range(n)]

dp = [[0]*(w+8) for _ in range(n+10)]
weight = [0] * (n)
value = [0] * (n)

for i in range(n):
    weight[i] = li[i][0]
    value[i] = li[i][1]

for i in range(n):
    for j in range(w+1):
        if j - weight[i] >= 0:
            dp[i+1][j] = max(dp[i+1][j], dp[i][j - weight[i]] + value[i])
        dp[i+1][j] = max(dp[i+1][j], dp[i][j])

print(dp[n][w])

### FIXED CODE ###

n, w = map(int, input().split())
li = [list(map(int, input().split())) for _ in range(n)]

dp = [[0]*(w+8) for _ in range(n+10)]
weight = [0] * (n)
value = [0] * (n)

for i in range(n):
    weight[i] = li[i][0]
    value[i] = li[i][1]

for i in range(n):
    for j in range(w+1):
        if j - weight[i] >= 0:
            dp[i+1][j] = max(dp[i+1][j], dp[i][j - weight[i]] + value[i])
        dp[i+1][j] = max(dp[i+1][j], dp[i][j])

print(dp[n][w])
H, W = map(int,input().split())
A = [list(map(int,input().split())) for i in range(H)]
n = 0
memo = []

for x in range(W):
  for y in range(H-1):
    if A[y][x]%2 == 1:
      A[y][x] -= 1
      A[y+1][x] += 1
      n += 1
      memo.append([y+1,x+1,y+2,x+1])
for x in range(W):
  if A[H-1][x]%2 == 1:
    A[H-1][x] -= 1
    A[H-1][x+1] += 1
    memo.append([H,x+1,H,x+2])
    n += 1
print(n)
for i in range(n):
  print(" ".join(map(str,memo[i])))

### FIXED CODE ###

H, W = map(int, input().split())
a = [list(map(int, input().split())) for i in range(H)]
N = 0
ans = []
for x in range(W):
  for y in range(H-1):
    if a[y][x]%2 == 1:
      a[y][x] -= 1
      a[y+1][x] += 1
      ans.append([y+1,x+1,y+2,x+1])
      N += 1
for x in range(W-1):
  if a[H-1][x]%2 == 1:
    a[H-1][x] -= 1
    a[H-1][x+1] += 1
    ans.append([H,x+1,H,x+2])
    N += 1
print(N)
for i in ans:
  print(" ".join(map(str,i)))
s=sorted(list(input());a=s.index('1');print(2*min(a,len(s)-a))

### FIXED CODE ###

s=sorted(list(input()))
if s[0]==s[-1]:
  print(0)
else:
  a=s.index('1')
  print(2*min(a,len(s)-a))
n = int(input())
x = input()
 
# 元のpopcount
original_pop_count = x.count('1')
# 反転して-1count
one_pop_count = original_pop_count - 1
# 反転して+1count
zero_pop_count = original_pop_count + 1
 
# ±1それぞれにおける余り
if one_pop_count = 0:
  one_mod = 0
else:
  one_mod = int(x, 2) % one_pop_count
zero_mod = int(x, 2) % zero_pop_count
 
# f の前計算 
f = [0] * 220000
pop_count = [0] * 220000
for i in range(1, 220000):
    pop_count[i] = pop_count[i//2] + i % 2
    f[i] = f[i % pop_count[i]] + 1
 
# pow2 の前計算
one_pow2 = [1] * 220000
zero_pow2 = [1] * 220000
for i in range(1, 220000):
    if one_pop_count != 0:
        one_pow2[i] = one_pow2[i-1] * 2 % one_pop_count
    zero_pow2[i] = zero_pow2[i-1] * 2 % zero_pop_count
    
# n-1, n-2, ,, 0
for i in range(n-1, -1, -1):
    if x[n-1-i] == '1':
        if one_pop_count != 0:
            nxt = one_mod
            # - 2^i % 2
            nxt -= one_pow2[i]
            nxt %= one_pop_count
            print(f[nxt] + 1)
        else:
            print(0)
    if x[n-1-i] == '0':
        nxt = zero_mod
        nxt += zero_pow2[i]
        # + 2^i % 2
        nxt %= zero_pop_count
        print(f[nxt] + 1)

### FIXED CODE ###

n = int(input())
x = input()
 
# 元のpopcount
original_pop_count = x.count('1')
# 反転して-1count
one_pop_count = original_pop_count - 1
# 反転して+1count
zero_pop_count = original_pop_count + 1
 
# ±1それぞれにおける余り
if one_pop_count == 0:
  one_mod = 0
else:
  one_mod = int(x, 2) % one_pop_count
zero_mod = int(x, 2) % zero_pop_count
 
# f の前計算 
f = [0] * 220000
pop_count = [0] * 220000
for i in range(1, 220000):
    pop_count[i] = pop_count[i//2] + i % 2
    f[i] = f[i % pop_count[i]] + 1
 
# pow2 の前計算
one_pow2 = [1] * 220000
zero_pow2 = [1] * 220000
for i in range(1, 220000):
    if one_pop_count != 0:
        one_pow2[i] = one_pow2[i-1] * 2 % one_pop_count
    zero_pow2[i] = zero_pow2[i-1] * 2 % zero_pop_count
    
# n-1, n-2, ,, 0
for i in range(n-1, -1, -1):
    if x[n-1-i] == '1':
        if one_pop_count != 0:
            nxt = one_mod
            # - 2^i % 2
            nxt -= one_pow2[i]
            nxt %= one_pop_count
            print(f[nxt] + 1)
        else:
            print(0)
    if x[n-1-i] == '0':
        nxt = zero_mod
        nxt += zero_pow2[i]
        # + 2^i % 2
        nxt %= zero_pop_count
        print(f[nxt] + 1)
n,m=map(int,input().split())
a=list(map(int,input().split()))
mod=1/(4*m)
ch=sum(a)*mod
r=0
for i in range(n):
  if a[i]>=ch:
    r+=1
  if r==m:
    print('Yes')
    break
else:
  print('No')
    

### FIXED CODE ###

a,b,c = input().split()
print(c+' '+a+' '+b)
N = int(input())
T = list(map(int, input().split()))
M = int(input())

P, X = [], []
for i in range(M):
    pi, xi = map(int, input().split)
    P.append(pi)
    X.append(xi)

count = 0
for i in T:
    count += T[i]

for i in X:
    count += X[i]
    count -= T[i]
    print(count

### FIXED CODE ###

N = int(input())
T = list(map(int, input().split()))
M = int(input())

P, X = [], []
for i in range(M):
    p1, x1 = map(int, input().split())
    P.append(p1)
    X.append(x1)

count = 0
for i in range(len(T)):
    count += T[i]

c = count

for i in range(M):
    count = c
    count += X[i]
    count -= T[P[i] - 1]
    print(count)
a, b, c, k = map(int, input().split())

ans = []

ans += [1] * a
ans += [0] * b
ans += [-1] * c

print(sum(ans[:min(k, a+b+c)]))

### FIXED CODE ###

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

# ans = []

# ans += [1] * a
# ans += [0] * b
# ans += [-1] * c

if k <= a:
    print(k)
elif k <= a + b:
    print(a)
elif k <= a + b + c:
    print(a - (k - a - b))

#print(sum(ans[:k]))
import sys

s = sys.stdin.readline().strip()

ans = 0
l = 0
r = len(s) - 1

while l != r:
    print("left", l, "right", r)
    if s[l] == "x" and s[r] == "x":
        l += 1
        r -= 1
    # rにxを足したとみなし、lを進める
    elif s[l] == "x":
        l += 1
        ans += 1
    # lにxを足したとみなし、rを進める
    elif s[r] == "x":
        r -= 1
        ans += 1
    elif s[l] != s[r]:
        print(-1)
        sys.exit()
    else:
        l += 1
        r -= 1

print(ans)

### FIXED CODE ###

import sys

s = sys.stdin.readline().strip()

ans = 0
l = 0
r = len(s) - 1

while l < r:
    # print("left", l, "right", r)
    if s[l] == "x" and s[r] == "x":
        l += 1
        r -= 1
    # rにxを足したとみなし、lを進める
    elif s[l] == "x":
        l += 1
        ans += 1
    # lにxを足したとみなし、rを進める
    elif s[r] == "x":
        r -= 1
        ans += 1
    elif s[l] != s[r]:
        print(-1)
        sys.exit()
    else:
        l += 1
        r -= 1

print(ans)
from collections import Counter

cmb = [0, 0, 1]
for i in range(3, 2 * 10 ** 5 + 1):
    cmb.append(int(cmb[i-1]*(i/(i-2))))

N = int(input())
A = list(map(int, input().split()))
c = Counter()
for i in A:
    c.update(str(i))
cmbL = {}
gsum = 0
for i in c.keys():
    tmp1 = cmb[int(c[i])]
    tmp2 = tmp1 - (tmp1 * (1 - 2/c[i]))
    cmbL[i] = [tmp1, tmp2]
    gsum += tmp1

for i in A:
    print(int(gsum - cmbL[str(i)][1]))


### FIXED CODE ###

from collections import Counter


from operator import mul
from functools import reduce


def cmbf(n, r):
    if (n < r):
        return 0
    r = min(n-r, r)
    if r == 0:
        return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1, r + 1))
    return over // under


N = int(input())
A = list(map(int, input().split()))
c = [0]*(N+1)

for A_i in A:
    c[A_i] += 1

gsum = 0
for i in range(1, N + 1):
    if (c[i] != 0):
        gsum += cmbf(c[i], 2)

for i in A:
    print(gsum-(c[i]-1))
N, M = map(int, input().split())
l = list(map(int, input().split()))

if M == 1:
    print(0)
else:
    l.sort()
    l_dist =[]
    for i in range(1, M):
        l_dist.append(abs(l[i]-l[i-1]))

    l_dist.sort()

    for i in range(N-1):
        l_dist.pop()

    print(sum(l_dist))

### FIXED CODE ###

N, M = map(int, input().split())
l = list(map(int, input().split()))

if (N>= M) or (M == 1):
    print(0)
else:
    l.sort()
    l_dist =[]

    for i in range(1, M):
        l_dist.append(abs(l[i]-l[i-1]))

    l_dist.sort()

    ans = sum(l_dist[:len(l_dist) - (N-1)])

    print(ans)
sum = 0
for i in range(n):
    x,u = input().split()
    sum += int(n) if u == "JPY" else float(x) * 380000
print(sum)

### FIXED CODE ###

n=int(input())
sum = 0
for i in range(n):
    x,u = input().split()
    sum += int(x) if u == 'JPY' else float(x) *380000
print(sum)
x,k,d=map(int,input().split())
a=divmod(abs(x),d)  
if a[0]<k:
  if a[1]==0 and a[0]%2==1:
    print(d)
  elif a[1]==0 and a[0]%2==0:
    print(0)
  elif a[1]!=0 and a[0]%2!=0:
    if x<0:
      print(d-a[1])
    else:
      print(abs(a[1]-d))
  else:
    print(a[1])
else:
  print(abs(x)-d*k)


### FIXED CODE ###

N=input()
if N=="RRR":
  print(3)
elif N=="SRR" or N=="RRS":
  print(2)
elif N=="SSR" or N=="RSR" or N=="SRS" or N=="RSS":
  print(1)
else:
  print(0)
N = int(input())
A = list(map(int, input().split()))
A.sort()
sum = 0
cnt = []
for i in range(N-1):
    if A[i] in cnt:
        sum += a
    else:
        for j in range(i+1, N):
            a = A[i] ^ A[j]
            sum += a
print(sum%1000000007)

### FIXED CODE ###

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

# あるbit列に対するコストの計算
def count(zerone):
    one = 0
    cnt = 0
    for i in range(N):
        flag = True
        if zerone[i] == 1:
            one += 1
            for j in range(len(A[i])):
                if A[i][j][1] != zerone[A[i][j][0]-1]:
                    flag = False
                    break
        if flag:
            cnt += 1
    if cnt == N:
        return one
    else:
        return 0

# bit列の列挙
def dfs(bits):
    if len(bits) == N:
        return count(bits)
    res = 0
    for i in range(2):
        bits.append(i)
        res = max(res, dfs(bits))
        bits.pop()
    return res

# main
N = int(input())
A = [[] for _ in range(N)]
for i in range(N):
    a = int(input())
    for _ in range(a):
        A[i].append([int(x) for x in input().split()])

ans = dfs([])
print(ans)
n = input()
s = 0
for i in range(n+1):
  l = list(i)
  if len(l) % 2 = 1:
    s += 1
print(s)

### FIXED CODE ###

n = int(input())
s = 0
for i in range(1,n+1):
  l = list(str(i))
  if len(l) % 2 == 1:
    s += 1
print(s)
(N, K) = map(lambda a: int(a), input().split())
A = map(lambda a: int(a), input().split())


def proc():
    global A
    B = [0 for _ in range(N)]

    for i in range(1,N):
        f = i - A[i]
        t = i + A[i]
        for j in range(max(1, f), min(N, t)):
            B[j] += 1
    
    A = B

for _ in range(1, K):
    proc()

print(" ".join(A))

### FIXED CODE ###

import numpy as np
from numba import njit

(N, K) = map(int, input().split())
A = np.array(list(map(int, input().split())))

@njit
def solve(N,K,A):
    for j in range(0, K):
        B = np.zeros(N, dtype=np.int64)

        for i in range(0,N):
            f = max(0, i - A[i])
            t = min(N-1, i + A[i])
            #for j in range(max(0, f), min(N, t)+1):
            #    B[j] += 1
            B[f] += 1
            if t+1 < N:
                B[t+1] -= 1
        A = np.cumsum(B)
        if np.all(A == N):
            return A
        i += 1
    return A
    

print(" ".join(map(str, solve(N,K,A))))
#!/usr/bin/env python3
import sys
from math import factorial

MOD = 1000000007  # type: int
from numba import jit

# @jit
def combination(n: int, r:int, mod=MOD):
    n1 = n+1
    r = min(r, n-r)
    numer = denom = 1
    for i in range(1, r+1):
        numer = numer * (n1-i) % mod
        denom = denom * i % mod
    return numer * pow(denom, mod-2, mod) % mod

def solve(X: int, Y: int):

    u = (2*Y - X)//3
    r = (X- u)//2

    if ((2*Y - X)%3!=0) or (r*u <0):
        print(0)
        return

    a = combination(u+r, u)
    print(a)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    X = int(next(tokens))  # type: int
    Y = int(next(tokens))  # type: int
    solve(X, Y)

if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/env python3
import sys
MOD = 1000000007  # type: int

def combination(n: int, r:int, mod=MOD):
    n1 = n+1
    r = min(r, n-r)
    numer = denom = 1
    for i in range(1, r+1):
        numer = numer * (n1-i) % mod
        denom = denom * i % mod
    return numer * pow(denom, mod-2, mod) % mod

def solve(X: int, Y: int):

    u = (2*Y - X)//3
    r = (X- u)//2

    if ((2*Y - X)%3!=0) or (r*u <0):
        print(0)
        return

    a = combination(u+r, u)
    print(a)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    X = int(next(tokens))  # type: int
    Y = int(next(tokens))  # type: int
    solve(X, Y)

if __name__ == '__main__':
    main()
a, b, c, d = map(int, input().split())
 
if abs(a-c) <= d:
  print("Yes")
else:
  if abs(a-b) <= d and abs(b-c) <=d:
    print(Yes)
  else:
    print("No")

### FIXED CODE ###

a, b, c, d = map(int, input().split())
 
if abs(a-c) <= d:
  print("Yes")
else:
  if abs(a-b) <= d and abs(b-c) <=d:
    print("Yes")
  else:
    print("No")
import math

N,X = map(int,input().split())
x = list(map(int,input().split()))
distance = []

for i in x:
    distance.append(abs(i-X))

while len(distance) > 1:
        cd = math.gcd(distance[0],distance[1])
        distance.append(cd)
        del distance[0]
        del distance[0]

print(distance[0])


### FIXED CODE ###

from functools import reduce
import fractions

N, X = map(int,input().split())
x = list(map(int,input().split()))
x = list(map(lambda x:abs(x-X), x))
x = reduce(lambda a,b: fractions.gcd(a,b), x)
print(x)
def del_list(L, I):
    diff = 0
    
    for i in I[::-1]:
        diff += L[i]
        del L[i]
    return L, diff

N, M = map(int, input().split())

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

bc = []
for i in range(M):
    bc.append(list(map(int, input().split())))
    

bc.sort(key=lambda x:x[1], reverse=True)

ans = 0
for BC in bc:
    if BC[1] <= A[0]:
#        print('break')
        break
    
    indexes = [i for i, x in enumerate(A) if x < BC[1]]
    
#    print(indexes)
    if len(indexes) > BC[0]:
        A, diff = del_list(A, indexes[0:BC[0]])
        ans += BC[1] * BC[0]

#        del(A[indexes[0:BC[0]]])
    elif len(indexes) == BC[0]:
        A, diff = del_list(A, indexes)
        ans += BC[1] * BC[0]
#        del(A[indexes])
    elif len(indexes) <= BC[0]:
        A, diff = del_list(A, indexes)
        ans += BC[1] * len(indexes)
        
#    print(ans)
#    print(A)

ans += sum(A)
        
print(ans)

### FIXED CODE ###

N, M = map(int, input().split())
A = list(map(int,input().split()))
A.sort()
bc = []
for i in range(M):
    bc.append(list(map(int, input().split())))
bc.sort(key=lambda x:x[1], reverse=True)

ans = 0

BC = bc[0]
bc_i = 0
ans += sum(A)
for i in range(len(A)):
    
    if BC[1] > A[i]:
        ans += BC[1] - A[i]
        BC[0] -= 1
    
    if BC[0] == 0:
        if bc_i == len(bc) - 1:
            break
        else:
            bc_i += 1
            BC = bc[bc_i]
        
print(ans)