Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

from collections import deque
 
n = int(input())
dll = deque()
 
for i in range(n):
    input_line = [str(s) for s in input().split()]
    if input_line[0] == "insert":
        dll.appendleft(input_line[1])
    elif len(dll) == 0:
        continue
    elif input_line[0] == "delete":
        try:
            dll.remove(input_line[1])
        except:
            pass
    elif input_line[0] == "deleteFirst":
        dll.popleft()
    else:
        dll.pop()
         
print(*dll)

### FIXED CODE ###

from collections import deque
   
n = int(input())
dll = deque()
   
for i in range(n):
    input_line = input().split()
    if input_line[0] == "insert":
        dll.appendleft(input_line[1])
    elif input_line[0] == "delete":
        try:
            dll.remove(input_line[1])
        except:
            pass
    elif input_line[0] == "deleteFirst":
        dll.popleft()
    else:
        dll.pop()
           
print(*dll)
### BUGGY CODE ###

import math
K = int(input())

def computeGCD(x, y):
    while (y):
        x, y = y, x % y

    return x

sum = 0
for a in range(1, K+1):
    for b in range(1, K+1):
        for c in range(1, K+1):
            sum += math.gcd(a, math.gcd(b, c))

print(sum)

### FIXED CODE ###

import math
K = int(input())

def computeGCD(x, y):
    while (y):
        x, y = y, x % y

    return x

sum = 0
for a in range(1, K+1):
    for b in range(1, K+1):
        intermediate = computeGCD(a, b)
        for c in range(1, K+1):
            sum += computeGCD(c, intermediate)

print(sum)
### BUGGY CODE ###

N,K = map(int,input().split())
A = list(map(int,input().split()))
val = 1
for i in range(N):
    if i < K:
        val *= A[i]
    else:
        if val < (val//(A[i-K])) * (A[i]):
            print('Yes')
        else:
            print('No')
        val //= (A[i-K])
        val *= A[i]


### FIXED CODE ###

N,K = map(int,input().split())
A = list(map(int,input().split()))
val = 1
for i in range(N):
    if i < K:
        continue
    else:
        if A[i-K] < A[i]:
            print('Yes')
        else:
            print('No')
### BUGGY CODE ###

n = int(input())
ta = []
for i in range(n):
    t, a = map(int, input().split())
    ta.append([t, a])

t = ta[0][0]
a = ta[0][1]
for i in range(1, n):
    p = ta[i][0] / (ta[i][0] + ta[i][1])
    while True:
        if p == t / (t + a):
            break
        if p < t / (t + a):
            a += 1
        else:
            t += 1

print(t + a)


### FIXED CODE ###

import math
from fractions import Fraction
N = int(input())

ta = [0] * N
ao = [0] * N

for i in range(N):
    t, a = map(int, input().split())
    if i == 0:
        ta[i] = t
        ao[i] = a
    else:
        tmp = max(math.ceil(Fraction(ta[i-1],t)), math.ceil(Fraction(ao[i-1],a)))
        ta[i] = t*tmp
        ao[i] = a*tmp

print(ta[-1]+ao[-1])
### BUGGY CODE ###

S = list(map(int, list(input())))

pops = 0
digi = 1
cnt = [0] * 2019
cnt[0] = 1

while S:
    s = S.pop()

    pops = (pops + s * digi) % 2019
    digi *= 10

    cnt[pops] += 1

ans = 0

for i in range(2019):
    ans += cnt[i] * (cnt[i] - 1) // 2

print(ans)

### FIXED CODE ###

S = list(map(int, list(input())))

pops = 0
digi = 1
cnt = [0] * 2019
cnt[0] = 1

while S:
    s = S.pop()

    pops = (pops + s * digi) % 2019
    digi = (10 * digi) % 2019

    cnt[pops] += 1

ans = 0

for i in range(2019):
    ans += cnt[i] * (cnt[i] - 1) // 2

print(ans)
### BUGGY CODE ###

n,q = map(int, input().split())
s = input()
tmp=[]
l,cnt=0,0
r=1
while r<=n:
  if 'AC' in s[l:r]:
    cnt+=1
    l=r
    tmp.append(cnt)
    tmp.append(cnt)
    r+=2
  else:
    tmp.append(cnt)
    r+=1

for i in range(q):
  l,r = map(int,input().split())
  print(tmp[r-1]-tmp[l-1])

### FIXED CODE ###

n,q = map(int, input().split())
s = input()
tmp=[0]
l,cnt=0,0
r=2
while r<=n:
  if 'AC' == s[l:r]:
    cnt+=1
    l=r
    tmp.append(cnt)
    tmp.append(cnt)
    r+=2
  else:
    tmp.append(cnt)
    l+=1
    r+=1
for i in range(q):
  l,r = map(int,input().split())
  print(tmp[r-1]-tmp[l-1])
### BUGGY CODE ###

# C - Prison

N, M = map(int, input().split())
ls = [i for i in range(1, N + 1)]
for _ in range(M):
    l, r = map(int, input().split())
    ls = set(ls) & set([i for i in range(l, r + 1)])

print(len(ls))


### FIXED CODE ###

# C - Prison

N, M = map(int, input().split())
left = 0
right = 10 ** 5
for _ in range(M):
    l, r = map(int, input().split())
    left, right = max(left, l), min(right, r)

print(len([i for i in range(left, right + 1)]) if left <= right else 0)
### BUGGY CODE ###

s = input()
if len(s) <= 3:
  print(0)
  exit()
chk = [0]*2019
for i in range(len(s)):
  c = int(s[i:])
  chk[c%2019] += 1
ans = chk[0]
for i in chk:
  ans += i*(i-1)//2
print(ans)

### FIXED CODE ###

import sys
input = sys.stdin.readline
s = input().strip()
if len(s) <= 3:
  print(0)
  exit()
c = 0
chk = [0]*2019
for i,si in enumerate(s[::-1]):
  c += int(si)*pow(10,i,2019)
  chk[c%2019] += 1
ans = chk[0]
for i in chk:
  ans += i*(i-1)//2
print(ans)
### BUGGY CODE ###

# -*- coding: utf-8 -*-

N,S = list(map(int, input().rstrip().split()))

# Add dummy data at first position
A_list = [None] + list(map(int, input().rstrip().split()))
#-----

mod = 998244353

dp = [ [0]*(S+1) for _ in range(N+1) ]
dp[0][0] = 1

for i in range(N):
    for j in range(S+1):
        if (j - A_list[i+1]) >=0:
            dp[i+1][j] = 2*dp[i][j] + dp[i][j - A_list[i+1]]
        else:
            dp[i+1][j] = 2*dp[i][j]
        
        dp[i+1][j] %= mod

print(dp[N][S])


### FIXED CODE ###

# -*- coding: utf-8 -*-

N,S = list(map(int, input().rstrip().split()))

# Add dummy data at first position
A_list = [None] + list(map(int, input().rstrip().split()))
#-----

mod = 998244353

dp = [ [0]*(S+1) for _ in range(N+1) ]
dp[0][0] = 1

for i in range(N):
    for j in range(S+1):
        if (j - A_list[i+1]) >=0:
            dp[i+1][j] = dp[i][j - A_list[i+1]]
        
        dp[i+1][j] += 2*dp[i][j]
        dp[i+1][j] %= mod

print(dp[N][S])
### BUGGY CODE ###

import sys
input = sys.stdin.readline
n = int(input())
a = list(map(int,input().split()))
mod = 10**9+7

a.sort(reverse = True)

l = len(bin(a[0])[2:])

ans  = 0
for b in range(l):
    count_1 = 0
    count_0 = 0
    for i in range(n):
        if (a[i] >> b) & 1:
            count_1 += 1
        else:
            count_0 += 1
    count_1 %= mod
    count_0 %= mod
    ans += (count_1 * count_0 * pow(2,b))%mod


print(ans%mod)

### FIXED CODE ###

import sys
input = sys.stdin.readline
n = int(input())
a = list(map(int,input().split()))
mod = 10**9+7

a.sort(reverse = True)

#l = len(bin(a[0])[2:])

ans  = 0
for b in range(60+1):
    count_1 = 0
    count_0 = 0
    for i in range(n):
        if (a[i] >> b) & 1:
            count_1 += 1
        else:
            count_0 += 1
    count_1 %= mod
    count_0 %= mod
    ans += (count_1 * count_0 * pow(2,b,mod))%mod


print(ans%mod)
### BUGGY CODE ###

# input
n, m = map(int, input().split())
la = sorted(list(map(int, input().split())), reverse=True)

while m > 0:
    d = 0
    for i in range(n):
        if i < n-1 and la[i] > la[i+1]:
            if la[i+1] > 0:
                d = la[i] // la[i+1]
            else:
                d = 1
            if d > m:
                d = m
                la[i] = la[i] // (2**d)
            else:
                la[i] = la[i] // (2**d)
            break
        else:
            la[i] = la[i] // 2
            d = 1
            break
    la.sort(reverse=True)
    #print(la)
    #print(d)
    m -= d

print(sum(la))


### FIXED CODE ###

import heapq as h

# input
n, m = map(int, input().split())
la = list(map(lambda x: int(x)*-1, input().split()))

h.heapify(la)

while m > 0:
    max = abs(la[0])
    h.heapreplace(la, (max // 2)*-1)
    m -= 1

print(abs(sum(la)))
### BUGGY CODE ###

N,M=map(int,input().split())
flag = False
v=[]
for i in range(M):
    a,b=map(int,input().split())
    v.append([a,b])
for i in range(M):
    for j in range(M):
        if v[i][1]==N:
            if v[j][1]==v[i][0] and v[j][0]==1:
                flag=True
                break
    if flag:
        print("POSSIBLE")
        break
else:
    print("IMPOSSIBLE")

### FIXED CODE ###

N,M=map(int,input().split())
x=[0]*(N+1)
y=[0]*(N+1)
for i in range(M):
    a,b=map(int,input().split())
    if a==1:
        x[b]=1
    if b==N:
        y[a]=1
for i in range(N+1):
    if x[i]==1 and y[i]==1:
        print("POSSIBLE")
        break
else:
    print("IMPOSSIBLE")
### BUGGY CODE ###

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

flag = True
count = 0
while(flag):
  for i in range(N):
    if A[i]%2:
      flag = False
      break
    else:
      count += 1
print(count)
  

### FIXED CODE ###

N = int(input())
A = list(map(int,input().split()))
 
flag = True
count = 0
while(flag):
  for i in range(N):
    if A[i]%2:
      flag = False
      break
    else:
      A[i] /= 2
  if flag:
    count += 1
print(count)
### BUGGY CODE ###

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

for i in range(M):
    A[A.index(max(A))] //= 2

print(sum(A))

### FIXED CODE ###

import heapq

N, M = map(int, input().split())
A = list(map(lambda x:int(x)*(-1), input().split()))

heapq.heapify(A)

for i in range(M):
    x = heapq.heappop(A) * -1
    x //= 2
    heapq.heappush(A, x*(-1))

print(sum(A)*(-1))
### BUGGY CODE ###

from sys import *
H, W = map(int, stdin.readline().split())
personY, personX = map(int, stdin.readline().split())
gH, gW = map(int, stdin.readline().split())

grid = [list(stdin.readline().strip()) for x in range(H)]
visited = [[10**10 for j in range(W)] for i in range(H)]
options = [(personY-1, personX-1)]

visited[personY-1][personX-1] = 0
while(options):
    y,x = options.pop()

    if y+1 < H and  grid[y+1][x] == ".":
        if visited[y+1][x] > visited[y][x]:
            options.append((y+1, x))
            visited[y+1][x] = visited[y][x]

    if  y-1 >= 0 and grid[y-1][x] == ".":
        if visited[y-1][x] > visited[y][x]:
            options.append((y-1, x))
            visited[y-1][x] = visited[y][x]

    if x+1 < W and grid[y][x+1] == ".":
        if visited[y][x+1] > visited[y][x]:
            options.append((y, x+1))
            visited[y][x+1] = visited[y][x]

    if   x-1 >= 0 and grid[y][x-1] == ".":
        if visited[y][x-1] > visited[y][x]:
            options.append((y, x-1))
            visited[y][x-1] = visited[y][x]
   #-------------------------------------------
    for Y in range(-2, 3):
        for X in range(-2, 3):
            if x+X >= 0 and x+X < W and y+Y >= 0 and y+Y < H and grid[y+Y][x+X] == ".":
                if visited[y+Y][x+X] > visited[y][x] +1:
                    options.append((y+Y, x+X))
                    visited[y+Y][x+X] = visited[y][x]+1

print(-1 if visited[gH-1][gW-1] == 10**10 else visited[gH-1][gW-1] )


### FIXED CODE ###

from sys import *
from collections import deque
H, W = map(int, stdin.readline().split())
personY, personX = map(int, stdin.readline().split())
gH, gW = map(int, stdin.readline().split())

grid = [list(stdin.readline().strip()) for x in range(H)]
visited = [ [10**10] * W for i in range(H)]
options = deque([[personY-1, personX-1]])

visited[personY-1][personX-1] = 0
while(options):
    y,x = options.popleft()
    if y+1 < H and  grid[y+1][x] == ".":
        if visited[y+1][x] > visited[y][x]:
            options.appendleft((y+1, x))
            visited[y+1][x] = visited[y][x]

    if  y-1 >= 0 and grid[y-1][x] == ".":
        if visited[y-1][x] > visited[y][x]:
            options.appendleft((y-1, x))
            visited[y-1][x] = visited[y][x]

    if x+1 < W and grid[y][x+1] == ".":
        if visited[y][x+1] > visited[y][x]:
            options.appendleft((y, x+1))
            visited[y][x+1] = visited[y][x]

    if x-1 >= 0 and grid[y][x-1] == ".":
        if visited[y][x-1] > visited[y][x]:
            options.appendleft((y, x-1))
            visited[y][x-1] = visited[y][x]
   #-------------------------------------------
    for Y,X in [(2,-2),(2,-1),(2,0),(2,1),(2,2), (1,-2),(1,-1),(1,1),(1,2), (0,-2),(0,2), (-1,-2),(-1,-1),(-1,1),(-1,2), (-2,-2),(-2,-1),(-2,0),(-2,1),(-2,2)]:
       if x+X >= 0 and x+X < W and y+Y >= 0 and y+Y < H and grid[y+Y][x+X] == ".":
           if visited[y+Y][x+X] > visited[y][x] +1:
               options.append((y+Y, x+X))
               visited[y+Y][x+X] = visited[y][x]+1

print(-1 if visited[gH-1][gW-1] == 10**10 else visited[gH-1][gW-1] )
### BUGGY CODE ###

s = input()
n=int(input())
l = [input().split(" ") for _ in range(n)]

x = 0
for i in range(n):
    if l[i][0]=='1':
        if x == 0:
            x = 1
        else:
            x = 0
    elif l[i][0]=='2':
        if x == 0:
            if l[i][1]=='1':
                s = l[i][2] + s
            else:
                s = s + l[i][2]
        else:
            if l[i][1]=='1':
                s = s + l[i][2]
            else:
                s = l[i][2] + s
if x == 0:
    print(s)
else:
    print(s[::-1])

### FIXED CODE ###

from collections import deque

s = deque(input())
n = int(input())
l = [input().split(" ") for _ in range(n)]

x = 0
for i in range(n):
    if l[i][0]=='1':
        if x == 0:
            x = 1
        else:
            x = 0
    elif l[i][0]=='2':
        if x == 0:
            if l[i][1]=='1':
                s.appendleft(l[i][2])
            else:
                s.append(l[i][2])
        else:
            if l[i][1]=='1':
                s.append(l[i][2])
            else:
                s.appendleft(l[i][2])

if x == 0:
    print(''.join(s))
else:
    print(''.join(reversed(s)))
### BUGGY CODE ###

import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
  return list(map(int,input().split()))
def m(): #複数文字
  return map(int,input().split())
def onem(): #Nとかの取得
  return int(input())
def s(x): #圧縮
  a = []
  if len(x) == 0:
    return []
  aa = x[0]
  su = 1
  for i in range(len(x)-1):
    if aa != x[i+1]:
      a.append([aa,su])
      aa = x[i+1]
      su = 1
    else:
      su += 1
  a.append([aa,su])
  return a
def jo(x): #listをスペースごとに分ける
  return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
  return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False

def pow_k(x, n):
    ans = 1
    while n:
        if n % 2:
            ans *= x
        x *= x
        n >>= 1
    return ans

"""
def nibu(x,n,r):
  ll = 0
  rr = r
  while True:
    mid = (ll+rr)//2

  if rr == mid:
    return ll
  if (ここに評価入れる):
    rr = mid
  else:
    ll = mid+1
"""

n,k = m()

if n == 0:
  if k == 0:
    print("0 0")
  else:
    print(-1)

elif n == 1:
  if k == 0:
    print("0 0 1 1")
  else:
    print(-1)
else:
  if 2<<(n-1) > k:
    po = ""

    op = ""

    for i in range((2<<(n-1))):
      if i == k:
        continue
      else:
        if po == "":
          po += str(i)
          op += str(i)
        else:
          po += " " + str(i)
          op = str(i) + " " + op
    print("{0} {1} {2} {3}".format(po,k,op,k))
  else:
    print(-1)




### FIXED CODE ###

import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
  return list(map(int,input().split()))
def m(): #複数文字
  return map(int,input().split())
def onem(): #Nとかの取得
  return int(input())
def s(x): #圧縮
  a = []
  if len(x) == 0:
    return []
  aa = x[0]
  su = 1
  for i in range(len(x)-1):
    if aa != x[i+1]:
      a.append([aa,su])
      aa = x[i+1]
      su = 1
    else:
      su += 1
  a.append([aa,su])
  return a
def jo(x): #listをスペースごとに分ける
  return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
  return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False

def pow_k(x, n):
    ans = 1
    while n:
        if n % 2:
            ans *= x
        x *= x
        n >>= 1
    return ans

"""
def nibu(x,n,r):
  ll = 0
  rr = r
  while True:
    mid = (ll+rr)//2

  if rr == mid:
    return ll
  if (ここに評価入れる):
    rr = mid
  else:
    ll = mid+1
"""

n,k = m()

if n == 0:
  if k == 0:
    print("0 0")
  else:
    print(-1)

elif n == 1:
  if k == 0:
    print("0 0 1 1")
  else:
    print(-1)
else:
  if 2<<(n-1) > k:
    po = []

    op = []

    for i in range((2<<(n-1))):
      if i == k:
        continue
      else:
        if po == "":
          po.append(i)
          op.append(i)
        else:
          po.append(i)
          op.append(i)
    op.reverse()
    print("{0} {1} {2} {3}".format(jo(po),k,jo(op),k))
  else:
    print(-1)
### BUGGY CODE ###

s = input()
ls = list(map(int,list(s)))
lt = []
for i in range(len(s)-1):
  lt.append(ls[i]+ls[i+1])

ans = 0
while 1 in lt:
  flg = 1
  lf = [1]*len(ls)
  for i in range(len(lt)):
    if flg == 1 and lt[i] == 1:
      lf[i] = 0
      lf[i+1] = 0
      ans += 2
      flg = 0
    elif flg == 0:
      flg = 1
  ls = [ls[i] for i,f in enumerate(lf) if f>0]
  lt = []
  for i in range(len(ls)-1):
  	lt.append(ls[i]+ls[i+1])

print(ans)

### FIXED CODE ###

s = input()
print(min(s.count('0'),s.count('1'))*2)
### BUGGY CODE ###

a=int(input())
lis=[]
for i in range(a):
  cou=0
  v=int(input())
  if lis==[]:
    lis+=[v]
  else:
    for i in range(len(lis)):
      if lis[i]==v:
        del lis[i]
        cou=1
        break
    if cou!=1:
      lis+=[v]
      
print(len(lis))

### FIXED CODE ###

a=int(input())
lis=[]
anlis=[]
for j in range(a):
  lis+=[int(input())]
lis.sort()
i=0
while i<len(lis):
  if i==len(lis)-1:
    anlis+=[lis[i]]
  elif lis[i]!=lis[i+1]:
    anlis+=[lis[i]]
  else:
    i+=1
  i+=1
print(len(anlis))
### BUGGY CODE ###

from operator import mul
from functools import reduce

def comb(n,r):
    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()))

aa = [0 for i in range(2*10**5)]
for i in range(n):
  aa[a[i]] += 1
 
for i in range(n):
  ans = 0
  aa[a[i]] -= 1
  for key in range(2*10**5):
    if aa[key] > 1:
      ans += comb(aa[key], 2)
  aa[a[i]] += 1
  print(ans)
  



### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))

aa = [0 for i in range(2*10**5)]
for i in range(n):
  aa[a[i]] += 1
 
ans = 0
for key in range(2*10**5):
  ans += aa[key]*(aa[key]-1)//2
    
for i in range(n):
  tmp1 = aa[a[i]]*(aa[a[i]]-1)//2
  aa[a[i]] -= 1
  tmp2 = aa[a[i]]*(aa[a[i]]-1)//2
  aa[a[i]] += 1
  print(ans-tmp1 + tmp2)
### BUGGY CODE ###

N = 5
ARR = [24, 11, 8, 3, 16]


N = 4
ARR = [5, 5, 5, 5]


N = 10
ARR = [33, 18, 45, 28, 8, 19, 89, 86, 2, 4]

N = int(input())
ARR = list(map(int,input().split()))

def calculate(n, arr):

    prr = [0 for i in range(2000005)]

    for i in range(n):
        start = arr[i]
        #
        # if prr[start] > 0:
        #     prr[start] = 2
        #     continue

        for j in range(start, 2000005, start):
            prr[j] = prr[j] + 1


    result = 0
    for i in range(n):
        start = arr[i]
        if prr[start] == 1:
            result += 1


    print(result)

calculate(N, ARR)


### FIXED CODE ###

N = 5
ARR = [24, 11, 8, 3, 16]

N = int(input())
ARR = list(map(int,input().split()))

def calculate(n, arr):
    maxValue = max(arr) + 1
    maxValue = 1000006
    krr = [0 for i in range(maxValue)]

    for start in arr:
        if krr[start] > 0:
            krr[start] = 2
            continue

        for i in range(start, maxValue, start):
            krr[i] += 1

    result = 0
    for ar in arr:
        if krr[ar] == 1:
            result = result + 1

    print(result)


calculate(N, ARR)
### BUGGY CODE ###

N, W = map(int, input().split())
wv = [list(map(int, input().split())) for _ in range(N)]
#品物は0～N-1と考えるので注意！

DP = [[-1]*(W+1) for _ in range(N-1)] #0~N-2
#DP[depth:0~N-1][0~W] calc()の結果をメモる
#DP[N-1][]については、W-pwsum>=N-1の重さならN-1の重さ
##W-pwsum<N-1の重さ なら 0
##→W-(N-1)>=pwsumとW-(N-1)<pwsumで場合分け
DP.append([0]*(W+1))
tmppwsum = 0
weiofMinus1, valofNminus1 = wv[N-1]
while W-weiofMinus1>=tmppwsum:
  DP[N-1][tmppwsum] = valofNminus1
  tmppwsum += 1


#合計pwsumの重さを入れた状態で、
#depth以降の品物を選ぶ場合の最大価値を返す関数
def calc(depth, pwsum):
  #メモ済みだったらメモした値を返す
  dp =  DP[depth][pwsum]
  if dp != -1: return dp
  
  nowWei, nowVal = wv[depth] #今選んでる品物のこと
  if pwsum + nowWei > W:
    #入れると重さ超過なので、入れずに次を考える
#    if depth >= N-1:
#      #今の品物が最後なら、以降得られる価値は0
#      DP[depth][pwsum] = 0
#      return 0
#    else:
    #次の品物が無い場合はDPで省かれている
      #次の品物がある場合、今のを入れずに次へいく
    irenai = calc(depth+1, pwsum)
    DP[depth][pwsum] = irenai
    return irenai
  if pwsum + nowWei <= W:
    #入れても大丈夫な場合
#    if depth >= N-1:
#      #今の品物が最後なら、今の品物しか入れられない
#      DP[depth][pwsum] = nowVal
#      return nowVal
    #次の品物が無い場合はDPで省かれている
      #次の品物がある場合、今のを入れる入れないの2択
    ireru = nowVal + calc(depth+1, pwsum+nowWei)
    irenai = calc(depth+1, pwsum)
    ans = max(ireru, irenai)
    DP[depth][pwsum] = ans
    return ans
    
print(calc(0, 0))

### FIXED CODE ###

N, W = map(int, input().split())
wv = [list(map(int, input().split())) for _ in range(N)]
#品物は0～N-1と考えるので注意！

DP = [0]*(W+1) #0~W
#各iにつき、残り重さがWの時の最大価値をDPに入れる


#i=N-1までいった時のmax(DP)が答え
for i in range(0, N, 1): #0~N-1
  w, v = wv[i]
  #残りwei(W-DPの2個目の添字)がw未満の場合入れられない
  #入れない場合は変えなければいい
  for nw in range(W, w-1, -1):
    iretaV = DP[nw-w] + v
    if iretaV > DP[nw]:
      DP[nw] = iretaV

print(max(DP))
### BUGGY CODE ###

l,r=map(int,input().split())
L=[]
ans=2019
mod=0
for i in range(r-l+1):
    L.append(l+i)
for i in range(len(L)):
    for j in range(len(L)):
        if i!=j:
            mod=L[i]*L[j]%2019
            ans=min(ans,mod)
    if ans==0:
        break
print(ans)

### FIXED CODE ###

l,r=map(int,input().split())
L=[]
ans=2019
mod=0
for i in range(r-l+1):
    L.append((l+i)%2019)
    if L.count((l+i)%2019)>1:
            break
for i in range(len(L)):
    for j in range(len(L)):
        if i!=j:
            mod=L[i]*L[j]%2019
            ans=min(ans,mod)
    if ans==0:
        break
print(ans)
### BUGGY CODE ###

N = int(input())
sum = 0
while N > 0:
    sum += N % 10
    N = N // 10
if sum % 9 == 0:
    print('Yes')
else:
    print('No')


### FIXED CODE ###

N = input()
s = [char for char in N]
sum_ = 0
for char in s:
    sum_ += int(char)
if sum_ % 9 == 0:
    print('Yes')
else:
    print('No')
### BUGGY CODE ###

import math


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

A.sort()

R = 0
M = []

if len(A) == 2:
    print(A[1], A[0])
else:
    for i in range(n):
        a = A[n-1-i]
        k = a / 2
        B = []
        C = []
        frac_a = math.factorial(a)
        if R > frac_a // (math.factorial(a-math.ceil(a/2)) ** 2):
            break
        for j in range(n):
            if A[j] < k:
                B.append(A[j])
            else:
                C.append(A[j])
                break
        b = B[-1]
        c = C[0]
        r_b = frac_a // (math.factorial(a-b) * math.factorial(b))
        r_c = frac_a // (math.factorial(a-c) * math.factorial(c))
        if r_b >= r_c and r_b > R:
            M = [a, b]
            R = r_b
        elif r_c >= r_b and r_c > R:
            M = [a, c]
            R = r_c

    print(M[0], M[1])


### FIXED CODE ###

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

A.sort()

if len(A) == 2:
    print(A[1], A[0])
else:
    a = A[-1]
    k = a / 2
    B = [a for a in A if a <  k]
    C = [a for a in A if a >= k]

    if k - B[-1] > C[0] - k:
        print(a, C[0])
    else:
        print(a, B[-1])
### BUGGY CODE ###

n, k = map(int, input().split())
l = []
for i in range(n):
    l.append(int(input()))

root = [1]*n

for i in range(n)[-2::-1]:
    num = 0
    for j in range(i + 1, n):
        if abs(l[i] - l[j]) <= k:
            num = max(num, root[j])
    root[i] += num

print(max(root))

### FIXED CODE ###

n, k = map(int, input().split())
l = []
for i in range(n):
    l.append(int(input()))

root = [1]*n

for i in range(n)[-2::-1]:
    num = 0
    for j in range(i + 1, i + 200):
        if j >= n:
            break
        if abs(l[i] - l[j]) <= k:
            num = max(num, root[j])
    root[i] += num

print(max(root))