CodeEff/ECCO huggingface dataset:
# Original solution
from collections import deque

while(True):
    W, H = list(map(int, input().split()))
    if not W: break
    tx,ty = list(map(int, input().split()))
    kx,ky = list(map(int, input().split()))
    ma = [[False]*(W+2) for _ in range(H+2)]
    for i in range(1,H+1):
        for j,a in enumerate(input().split()):
            ma[i][j+1] = bool(1-int(a))
    from pprint import pprint
    que = deque([[tx,ty,kx,ky,0]])
    pas = set()
    ans = "NA"
    while(que):
        tx,ty,kx,ky,c = que.popleft()
        if c > 100: break
        if tx == kx and ty == ky:
            ans = c
            break
        for dx,dy in [[-1,0],[0,-1],[1,0],[0,1]]:
            tdx, tdy = [ dx, dy] if ma[ty+dy][tx+dx] else [0,0]
            kdx, kdy = [-dx,-dy] if ma[ky-dy][kx-dx] else [0,0]
            if (tx+tdx,ty+tdy,kx+kdx,ky+kdy) in pas: continue
            que.append([tx+tdx,ty+tdy,kx+kdx,ky+kdy,c+1])
            pas.add((tx+tdx,ty+tdy,kx+kdx,ky+kdy))
    print(ans)



# Optimized solution
# from line_profiler import LineProfiler
from collections import deque

def main():
    while(True):
        W, H = list(map(int, input().split()))
        if not W: break
        tx,ty = list(map(int, input().split()))
        kx,ky = list(map(int, input().split()))
        ma = [[False]*(W+2) for _ in range(H+2)]
        for i in range(1,H+1):
            for j,a in enumerate(input().split()):
                ma[i][j+1] = bool(1-int(a))
        from pprint import pprint
        que = deque([[tx,ty,kx,ky,0]])
        pas = set()
        ans = "NA"
        while(que):
            tx,ty,kx,ky,c = que.popleft()
            if c > 100: break
            if tx == kx and ty == ky:
                ans = c
                break
            for dx,dy in [[-1,0],[0,-1],[1,0],[0,1]]:
                tdx, tdy = [ dx, dy] if ma[ty+dy][tx+dx] else [0,0]
                kdx, kdy = [-dx,-dy] if ma[ky-dy][kx-dx] else [0,0]
                if (tx+tdx,ty+tdy,kx+kdx,ky+kdy) in pas: continue
                que.append([tx+tdx,ty+tdy,kx+kdx,ky+kdy,c+1])
                pas.add((tx+tdx,ty+tdy,kx+kdx,ky+kdy))
        print(ans)

if __name__ == "__main__":
    # prf = LineProfiler()
    # prf.add_function(main)
    # prf.runcall(main)
    # prf.print_stats()
    main()
# Original solution
# from line_profiler import LineProfiler
from collections import deque
from sys import stdin

def main():
    while(True):
        W, H = list(map(int, stdin.readline().split()))
        if not W: break
        tx,ty = list(map(int, stdin.readline().split()))
        kx,ky = list(map(int, stdin.readline().split()))
        ma = [[False]*(W+2) for _ in range(H+2)]
        for i in range(1,H+1):
            for j,a in enumerate(stdin.readline().split()):
                ma[i][j+1] = bool(1-int(a))
        que = deque([[tx,ty,kx,ky,0]])
        pas = set()
        ans = "NA"
        while(que):
            tx,ty,kx,ky,c = que.popleft()
            if not(tx-kx or ty-ky):
                ans = c
                break
            for dx,dy in [[-1,0],[0,-1],[1,0],[0,1]]:
                tdx, tdy = [ dx, dy] if ma[ty+dy][tx+dx] else [0,0]
                kdx, kdy = [-dx,-dy] if ma[ky-dy][kx-dx] else [0,0]
                if (tx+tdx,ty+tdy,kx+kdx,ky+kdy) in pas: continue
                if c+1 > 100: continue
                que.append([tx+tdx,ty+tdy,kx+kdx,ky+kdy,c+1])
                pas.add((tx+tdx,ty+tdy,kx+kdx,ky+kdy))
        print(ans)

if __name__ == "__main__":
    # prf = LineProfiler()
    # prf.add_function(main)
    # prf.runcall(main)
    # prf.print_stats()
    main()


# Optimized solution
# from line_profiler import LineProfiler
from collections import deque
from sys import stdin

def main():
    while(True):
        W, H = list(map(int, stdin.readline().split()))
        if not W: break
        tx,ty = list(map(int, stdin.readline().split()))
        kx,ky = list(map(int, stdin.readline().split()))
        ma = [[False]*(W+2) for _ in range(H+2)]
        for i in range(1,H+1):
            for j,a in enumerate(stdin.readline().split()):
                ma[i][j+1] = bool(1-int(a))
        que = deque([[tx,ty,kx,ky,0]])
        pas = set()
        ans = "NA"
        while(que):
            tx,ty,kx,ky,c = que.popleft()
            if tx == kx and ty == ky:
                ans = c
                break
            for dx,dy in [[-1,0],[0,-1],[1,0],[0,1]]:
                tdx, tdy = ( dx, dy) if ma[ty+dy][tx+dx] else (0,0)
                kdx, kdy = (-dx,-dy) if ma[ky-dy][kx-dx] else (0,0)
                ttx,tty,kkx,kky = tx+tdx,ty+tdy,kx+kdx,ky+kdy
                if (ttx,tty,kkx,kky) in pas: continue
                if c+1 > 100: continue
                que.append([ttx,tty,kkx,kky,c+1])
                pas.add((ttx,tty,kkx,kky))
        print(ans)

if __name__ == "__main__":
    # prf = LineProfiler()
    # prf.add_function(main)
    # prf.runcall(main)
    # prf.print_stats()
    main()
# Original solution
# from line_profiler import LineProfiler
from collections import deque
from sys import stdin

def main():
    while(True):
        W, H = list(map(int, stdin.readline().split()))
        if not W: break
        tx,ty = list(map(int, stdin.readline().split()))
        kx,ky = list(map(int, stdin.readline().split()))
        ma = [[0]+[abs(1-int(a)) for a in stdin.readline().split()]+[0] for i in range(H)]
        ma = [[0]*(W+2)] + ma + [[0]*(W+2)]
        que = deque([[tx,ty,kx,ky,0]])
        pas = set()
        ans = "NA"
        while(que):
            tx,ty,kx,ky,c = que.popleft()
            if tx == kx and ty == ky:
                ans = c
                break
            if c+1 > 100: continue
            for dx,dy in [[-1,0],[0,-1],[1,0],[0,1]]:
                tdx, tdy =  dx * ma[ty+dy][tx+dx],  dy * ma[ty+dy][tx+dx]
                kdx, kdy = -dx * ma[ky-dy][kx-dx], -dy * ma[ky-dy][kx-dx]
                ttx,tty,kkx,kky = tx+tdx,ty+tdy,kx+kdx,ky+kdy
                if (ttx,tty,kkx,kky) in pas: continue
                que.append([ttx,tty,kkx,kky,c+1])
                pas.add((ttx,tty,kkx,kky))
        print(ans)

if __name__ == "__main__":
    # prf = LineProfiler()
    # prf.add_function(main)
    # prf.runcall(main)
    # prf.print_stats()
    main()


# Optimized solution
# from line_profiler import LineProfiler
from collections import deque
from sys import stdin

def main():
    while(True):
        W, H = list(map(int, stdin.readline().split()))
        if not W: break
        tx,ty = list(map(int, stdin.readline().split()))
        kx,ky = list(map(int, stdin.readline().split()))
        ma = [[False]+[bool(1-int(a)) for a in stdin.readline().split()]+[False] for i in range(H)]
        ma = [[False]*(W+2)] + ma + [[False]*(W+2)]
        que = deque([[tx,ty,kx,ky,0]])
        pas = set()
        ans = "NA"
        while(que):
            tx,ty,kx,ky,c = que.popleft()
            if tx == kx and ty == ky:
                ans = c
                break
            if c+1 > 100: continue
            for dx,dy in [[-1,0],[0,-1],[1,0],[0,1]]:
                tdx, tdy = ( dx, dy) if ma[ty+dy][tx+dx] else (0,0)
                kdx, kdy = (-dx,-dy) if ma[ky-dy][kx-dx] else (0,0)
                ttx,tty,kkx,kky = tx+tdx,ty+tdy,kx+kdx,ky+kdy
                if (ttx,tty,kkx,kky) in pas: continue
                que.append([ttx,tty,kkx,kky,c+1])
                pas.add((ttx,tty,kkx,kky))
        print(ans)

if __name__ == "__main__":
    # prf = LineProfiler()
    # prf.add_function(main)
    # prf.runcall(main)
    # prf.print_stats()
    main()
# Original solution
def match(ch1, ch2):
    return ch1 == ch2 or ch1 == '?' or ch2 == '?'

def solve():
    MAXLEN = 2000
    a = input()
    b = input()
    c = input()
    lA = len(a); lB = len(b); lC = len(c)
    MAXLEN = max(lA, lB, lC)
    ab = [True for i in range(10*MAXLEN)]
    ac = [True for i in range(10*MAXLEN)]
    bc = [True for i in range(10*MAXLEN)]
    for i in range(lA):
        for j in range(lB):
            if not match(a[i], b[j]):
                ab[i - j + 5 * MAXLEN] = False
    for i in range(lA):
        for j in range(lC):
            if not match(a[i], c[j]):
                ac[i - j + 5 * MAXLEN] = False
    for i in range(lB):
        for j in range(lC):
            if not match(b[i], c[j]):
                bc[i - j + 5 * MAXLEN] = False
    ret = lA + lB + lC
    for i in range(-2*MAXLEN, 2*MAXLEN+1):
        for j in range(-2*MAXLEN, 2*MAXLEN+1):
            if ab[i + 5*MAXLEN] and ac[j + 5*MAXLEN] and bc[j - i + 5*MAXLEN]:
                L = min(0, i, j)
                R = max(lA, lB + i, lC + j)
                ret = min(ret, R - L)
    print(ret)

if __name__ == '__main__':
    solve()


# Optimized solution
def match(ch1, ch2):
    return ch1 == ch2 or ch1 == '?' or ch2 == '?'

def solve():
    MAXLEN = 2000
    a = input()
    b = input()
    c = input()
    lA = len(a); lB = len(b); lC = len(c)
    MAXLEN = max(lA, lB, lC)
    ab = [True for i in range(10*MAXLEN)]
    ac = [True for i in range(10*MAXLEN)]
    bc = [True for i in range(10*MAXLEN)]
    for i in range(lA):
        for j in range(lB):
            if not match(a[i], b[j]):
                ab[i - j + 5 * MAXLEN] = False
    for i in range(lA):
        for j in range(lC):
            if not match(a[i], c[j]):
                ac[i - j + 5 * MAXLEN] = False
    for i in range(lB):
        for j in range(lC):
            if not match(b[i], c[j]):
                bc[i - j + 5 * MAXLEN] = False
    ret = lA + lB + lC
    for i in range(-2*MAXLEN, 2*MAXLEN+1):
        for j in range(-2*MAXLEN, 2*MAXLEN+1):
            if i < -MAXLEN and j > 0:
                continue
            if i > MAXLEN and j < 0:
                continue
            if j < -MAXLEN and i > 0:
                continue
            if j > MAXLEN and i < 0:
                continue
            if ab[i + 5*MAXLEN] and ac[j + 5*MAXLEN] and bc[j - i + 5*MAXLEN]:
                L = min(0, i, j)
                R = max(lA, lB + i, lC + j)
                ret = min(ret, R - L)
    print(ret)

if __name__ == '__main__':
    solve()
# Original solution
def solve(N):
    d = 10 ** 7
    index = d // 2
    while True:
        k1 = index * (index - 1) // 2
        k2 = index * (index + 1) // 2
        if k1 <= N < k2:
            break
        elif k1 < N:
            index = (index + d) // 2
        else:
            d = index
            index = index // 2

    d = k2 - N
    return "\n".join([str(i) for i in range(1, index + 1) if i != d])


if __name__ == "__main__":
    N = int(eval(input()))
    print((solve(N)))


# Optimized solution
def solve(N):
    d = 10 ** 7
    index = d // 2
    while True:
        k1 = index * (index - 1) // 2
        k2 = index * (index + 1) // 2
        if k1 < N <= k2:
            break
        elif k1 <= N:
            index = (index + d) // 2
        else:
            d = index
            index = index // 2

    d = k2 - N
    return "\n".join([str(i) for i in range(1, index + 1) if i != d])


if __name__ == "__main__":
    N = int(eval(input()))
    print((solve(N)))
# Original solution
# -*- coding: utf-8 -*-
n = int(eval(input()))

for k in range(1,n+1):
    s = k*(k+1)//2
    if s==n:
        res = set(range(1,k+1))
        break
    if s>=n and (s-n)<=k:
        res = set(range(1,k+1))
        res.remove(s-n)

for r in res:
    print(r)


# Optimized solution
# -*- coding: utf-8 -*-
n = int(eval(input()))

for k in range(1,n+1):
    s = k*(k+1)//2
    if s==n:
        res = set(range(1,k+1))
        break
    if s>=n and (s-n)<=k:
        res = set(range(1,k+1))
        res.remove(s-n)
        break

for r in res:
    print(r)
# Original solution
N = int(eval(input()))
n = tri = 1
while tri < N:
    n += 1
    tri += n
for i in range(1,n+1):
    if i == tri - N: continue
    print(i)

# Optimized solution
N = int(input())
m = s = 1
while s < N:
    m += 1
    s += m

ans = [m]
rem = N-m
if rem:
    for n in range(m-1,0,-1):
        if n <= rem:
            ans.append(n)
            rem -= n
            if rem==0: break

print(*reversed(ans), sep='\n')
# Original solution
n = int(eval(input()))
s = 0
cnt = 1
while True:
    s += cnt
    if s < n <= s+cnt+1:
        use = cnt+1
        sub = use*(use+1)//2 - n
        for i in range(use):
            if i+1 == sub:
                continue
            print((i+1))
        exit()
    else:
        cnt += 1


# Optimized solution
n = int(eval(input()))
if n == 1:
    print((1))
    exit()
s = 0
cnt = 1
while True:
    s += cnt
    if s < n <= s+cnt+1:
        use = cnt+1
        sub = use*(use+1)//2 - n
        for i in range(use):
            if i+1 == sub:
                continue
            print((i+1))
        exit()
    else:
        cnt += 1
# Original solution
# Author: cr4zjh0bp
# Created: Sun Mar 22 23:25:40 UTC 2020
import sys
 
stdin = sys.stdin
inf = 1 << 60
mod = 1000000007
 
ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

from collections import Counter

s = ns()
c = Counter(s)
print(("yes" if len(s) == len(c) else "no"))

# Optimized solution
# Author: cr4zjh0bp
# Created: Sun Mar 22 23:25:40 UTC 2020
import sys
 
stdin = sys.stdin
inf = 1 << 60
mod = 1000000007
 
ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

s = ns()
print(("yes" if len(s) == len(set(s)) else "no"))
# Original solution
s = input()
l = list(s)

ans = "yes"

l.sort()

for i in range(len(s)-1):
    if l[i] == l[i+1]:
        ans = "no"
        break

print(ans)

# Optimized solution
L = list(input())
print("yes" if len(L) == len(set(L)) else "no")
# Original solution
def solve(a, b, c, d):
  for k in range(29, -1, -1):
    block_size = 3**k
    box_size = block_size * 3
    x1, y1, x2, y2 = [x//block_size for x in (a, b, c, d)]
    x1, x2 = sorted([x1, x2])
    y1, y2 = sorted([y1, y2])
    if x1!=x2 and y1!=y2:
      return abs(a-c)+abs(b-d)
    if x1==x2 and x1%3==1 and (y1+1)//3*3+1<y2:
      a, c = [x%box_size for x in (a, c)]
      return min(a+c-2*block_size+2, 4*block_size-a-c)+abs(b-d)
    elif y1==y2 and y1%3==1 and (x1+1)//3*3+1<x2:
      b, d = [x%box_size for x in (b, d)]
      return min(b+d-2*block_size+2, 4*block_size-b-d)+abs(a-c)
  return abs(a-c)+abs(b-d)

for i in range(int(eval(input()))):
  print((solve(*[int(x)-1 for x in input().split()])))


# Optimized solution
def solve(a, b, c, d):
  a, c = sorted([a, c])
  b, d = sorted([b, d])
  for k in range(30, 0, -1):
    block_size = 3**k
    box_size = block_size // 3
    x1, y1, x2, y2 = [x//box_size for x in (a, b, c, d)]
    if x1 != x2 and y1 != y2:
      return c-a + d-b
    elif x1 == x2 and x1%3 == 1 and (y1+1)//3*3+1 < y2:
      shifted = (a+c) % (2*block_size)
      return min(shifted-2*box_size+2, 4*box_size-shifted) + d-b
    elif y1 == y2 and y1%3 == 1 and (x1+1)//3*3+1 < x2:
      shifted = (b+d) % (2*block_size)
      return min(shifted-2*box_size+2, 4*box_size-shifted) + c-a
  return c-a + d-b

for i in range(int(eval(input()))):
  print((solve(*[int(x)-1 for x in input().split()])))
# Original solution
from sys import stdin, stdout
import math
import bisect
import re

s, w = list(map(int, stdin.readline().strip().split()))

stdout.writelines('unsafe\n' if w >= s else 'safe\n')


# Optimized solution
a, b = [int(a) for a in input().split()]
print(("unsafe" if a <= b else "safe"))
# Original solution
s,w = list(map(int,input().split()))

if s <= w:
    print("unsafe")
else:
    print("safe")

# Optimized solution
s,w = list(map(int,input().split()))

if w >= s:
    print("unsafe")
else:
    print("safe")
# Original solution
import sys
input = lambda: sys.stdin.readline().rstrip()
safe = lambda boolean: print('safe') if boolean else print('unsafe')
ints = lambda: list(map(int, input().split()))
s,w = ints()
safe(s>w)


# Optimized solution
s,w=map(int,input().split());print('safe')if s>w else print('unsafe')
# Original solution
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    s, w = list(map(int, readline().split()))

    if w >= s:
        print("unsafe")
    else:
        print("safe")


if __name__ == '__main__':
    main()


# Optimized solution
s, w = list(map(int, input().split()))

if w >= s:
    print("unsafe")
else:
    print("safe")
# Original solution
a, b = [int(a) for a in input().split()]
print(("unsafe" if a <= b else "safe"))

# Optimized solution
a, b=[int(yy) for yy in input().split()]
if b>=a:
	print('unsafe')
else:
	print("safe")
# Original solution
def main():
    ans = 'safe'
    s,w = list(map(int, input().split()))
    if w >= s:
        ans = 'unsafe'
    
    print(ans)

if __name__ == '__main__':
    main()

# Optimized solution
s,w = list(map(int, input().split()))
if s <= w:
  print('unsafe')
else:
  print('safe')
# Original solution
s , w = list(map(int, input().split()))

if w>=s:
    print("unsafe")
else:
    print("safe")

# Optimized solution
S, W =list(map(int,input().split()))
if W>=S:
    print("unsafe")
else:
    print("safe")
# Original solution
s, w = list(map(int, input().split()))
if w >= s:
    print('unsafe')
else:
    print('safe')

# Optimized solution
s, w = map(int, input().split())
print('unsafe') if w >= s else print('safe')
# Original solution


s,w = (int(x) for x in input().split())
# xl = map(int, input().split())

if w >= s:
	print('unsafe')
else:
	print('safe')


# Optimized solution
s,w = (int(x) for x in input().split())

if w >= s:
	print('unsafe')
else:
	print('safe')
# Original solution
S, W = list(map(int, input().split()))
if S>W:
  print("safe")
else:
  print("unsafe")

# Optimized solution
s, w = list(map(int, input().split()))
if s>w:
  print("safe")
else:
  print("unsafe")
# Original solution

def main():
    s,w = list(map(int,input().split()))
    if s <= w:
        print("unsafe")
    else:
        print("safe")

if __name__ == '__main__':
    main()


# Optimized solution
def main():
    s,w = list(map(int,input().split()))
    answer = "unsafe" if w >= s else "safe"
    print(answer)
if __name__ == '__main__':
    main()
# Original solution
s,w = list(map(int,input().split()))
print((["safe","unsafe"][w>=s]))

# Optimized solution
s,w=list(map(int,input().split()));print((["","un"][w>=s]+"safe"))
# Original solution
import sys

sys.setrecursionlimit(10 ** 7)
rl = sys.stdin.readline


def solve():
    s, w = list(map(int, rl().split()))
    if s > w:
        print('safe')
    else:
      print('unsafe')
    

if __name__ == '__main__':
    solve()


# Optimized solution
def solve():
    S, W = list(map(int,input().split()))
    if S > W:
        print("safe")
    else:
        print("unsafe")
    

if __name__ == '__main__':
    solve()
# Original solution
s,w=list(map(int,input().split()))
if s>w:
    print("safe")
else:
    print("unsafe")

# Optimized solution
s,w=list(map(int,input().split()))
if s>w:
    print("safe")
elif s<=w:
    print("unsafe")
# Original solution
S, W = list(map(int, input().split()))

if W >= S:
    print('unsafe')
else:
    print('safe')

# Optimized solution
S, W = input().split()
if int(W) >= int(S):
  print('unsafe')
else:
  print('safe')
# Original solution
def issafe(S,W):
    if S > W:
        return "safe"
    return "unsafe"

S,W = list(map(int,input().split()))
print((issafe(S,W)))


# Optimized solution
def main():
  s,w = list(map(int,input().split()))
  if s>w:
    print("safe")
  else:
    print("unsafe")

main()
# Original solution
s, w = list(map(int,input().split()))

if s <= w:
    print('unsafe')
else:
    print('safe')

# Optimized solution
s,w = list(map(int,input().split()))

if s <= w:
    print('unsafe')
elif s > w:
    print('safe')
# Original solution
MAX_VAL = 99999999999
while 1:
    n,m = list(map(int,input().split()))
    if n == 0:break
    costs = {x:[] for x in range(1,n+1)}
    min_cost = [[MAX_VAL for x in range(2)] for y in range(n+1)]
    for i in range(m):
        a,b,c = list(map(int,input().split()))
        costs[a].append((b,c))
        costs[b].append((a,c))

    spam = [(0,1,2)] #(cost,num,free tickets count)
    while len(spam) > 0:
        mc = min(spam)
        spam.remove(mc)

        tic_i = 0 if mc[2] == 2 else 1

        if mc[2] != 1 and min_cost[mc[1]][tic_i] != MAX_VAL:
            continue

        if mc[2] != 1:
            min_cost[mc[1]][tic_i] = mc[0]

        #移動できる場所の登録
        for cv in costs[mc[1]]:
            #チケット不使用
            if mc[2] != 1:
                spam.append((mc[0] + cv[1],cv[0],mc[2]))
            #チケット使用
            if mc[2] > 0:
                spam.append((mc[0],cv[0],mc[2]-1))

    #print(min_cost[n])
    print((min(min_cost[n])))

# Optimized solution
MAX_V = 999999999999999999999
while 1:
    n,m = list(map(int,input().split()))
    if n == 0:break
    costs = {x:[] for x in range(1,n+1)}
    passed = [[0 for x in range(2)] for y in range(n+1)]
    result = [MAX_V,MAX_V]
    for i in range(m):
        a,b,c = list(map(int,input().split()))
        costs[a].append((b,c))
        costs[b].append((a,c))

    spam = [(0,1,2)] #(cost,num,free tickets count)
    while len(spam) > 0:
        mc = min(spam)
        spam.remove(mc)

        tic_i = 0 if mc[2] == 2 else 1

        if mc[2] != 1 and passed[mc[1]][tic_i] != 0:
            continue

        if mc[2] != 1:
            passed[mc[1]][tic_i] = 1
            if n == mc[1]:
                result[tic_i] = mc[0]

        if max(result) < MAX_V:break

        #移動できる場所の登録
        for cv in costs[mc[1]]:
            #チケット不使用
            if mc[2] != 1:
                spam.append((mc[0] + cv[1],cv[0],mc[2]))
            #チケット使用
            if mc[2] > 0:
                spam.append((mc[0],cv[0],mc[2]-1))

    print((min(result)))
# Original solution
def resolve():
    n,x=list(map(int, input().split()))
    l=list(map(int, input().split()))
    l.sort()
    num=0
    cnt=0
    for i in range(n-1):
        if num+l[i]<=x:
            num+=l[i]
            cnt+=1
    if l[n-1]==x-num:
        cnt+=1
    print(cnt)
resolve()

# Optimized solution
def resolve():
    import sys
    n,x=list(map(int, input().split()))
    l=list(map(int, input().split()))
    l.sort()
    cnt=0
    for i in range(n):
        if l[i]<=x:
            x-=l[i]
            cnt+=1
        else:
            print(i)
            sys.exit()
    if cnt==n and x>0:
        cnt-=1
    print(cnt)
resolve()
# Original solution
def memoize(f):
    table = dict()
    def wrapper(x, i, a):
        key = (x, i)
        if key in table:
            return table[key]
        else:
            v = f(x, i, a)
            table[key] = v
            return v
    return wrapper

@memoize
def solve(x, i, a):
    if i == len(a) - 1:
        if a[i] == x:
            return 1
        else:
            return 0

    if x < a[i]:
        return 0
    else:
        m = solve(x - a[i], i + 1, a) + 1
        n = solve(x, i + 1, a)
        return max(m, n)

def main():
    n, x = [int(s) for s in input().split()]
    a = tuple(sorted(int(s) for s in input().split()))

    print((solve(x, 0, a)))

main()


# Optimized solution
def main():
    n, x = [int(s) for s in input().split()]
    a = [int(s) for s in input().split()]
    a.sort()

    cnt = 0
    for i, y in enumerate(a):
        if x < y:
            break
        x -= y
        cnt += 1
    else:
        # distribute to all child
        if x != 0:
            cnt -= 1
    print(cnt)

main()