qyliang/CodeNanoFix huggingface dataset:
Buggy code:
N,x = map(int,input().split())
a = sorted(map(int,input().split()),reverse=False)
ans = 0
for i in a:
    if x - i >= 0:
        x -= i
        ans += 1

if x > 0:
    ans -= 1

print(ans)

Fixed code:
N,x = map(int,input().split())
a = sorted(map(int,input().split()),reverse=False)
ans = 0

if x > sum(a):
    print(N - 1)

else:
    for i in a:
        x -= i
        if x >= 0:
            ans += 1
    print(ans)
Buggy code:
N, x = map(int, input().split())
a = list(map(int, input().split()))

a.sort()

cnt = 0
for i in range(N):
    if x - a[i] < 0:
        break
    cnt += 1
    x -= a[i]

print(cnt)

Fixed code:
N, x = map(int, input().split())
a = list(map(int, input().split()))

a.sort()

cnt = 0
for i in range(N):
    if x - a[i] >= 0:
        cnt += 1    
    x -= a[i]

if x <= 0:
    print(cnt)
else:
    print(cnt - 1)
Buggy code:
n, x = map(int, input().split())
a = map(int, input().split())
num = len(a)
a.sort(reverse=True)
for i in range(num):
    x -= a.pop()
    if x < 0:
        print(i)
        exit()
    if x == 0:
        print(i + 1)
        exit()
print(num - 1)

Fixed code:
n, x = map(int, input().split())
a = list(map(int, input().split()))
num = len(a)
a.sort(reverse=True)
for i in range(num):
    x -= a.pop()
    if x < 0:
        print(i)
        exit()
    if x == 0:
        print(i + 1)
        exit()
print(num - 1)
Buggy code:
N,X = map(int,input().split())
a = list(map(int,input().split()))
a.sort()

b = []
for i in range(N):
    b.append(0)
    
c = 0

for i in range(N):
    for j in range(i+1):
        b[i] += a[j]

for i in range(N):
    if b[i] <= X:
        c += 1
print(c)

Fixed code:
N,X = map(int,input().split())
a = list(map(int,input().split()))
a.sort()

b = []
for _ in range(N):
    b.append(0)
    
c = 0

for i in range(N):
    for j in range(i+1):
        b[i] += a[j]

for k in range(N-1):
    if b[k] <= X:
        c += 1
if b[N-1] == X:
    c += 1
print(c)
Buggy code:
n,x=map(int,input().split())
a=sorted([int(i)for i in input().split()])
res=0
if sum(a)==x:
    res=n
else:
    for i in range(n):
        if sum(a[:i])<=x:res=len(a[:i])-1
print(max(0,res))

Fixed code:
n,x=map(int,input().split())
a=sorted([int(i)for i in input().split()])
res=0
if sum(a)==x:
    res=n
else:
    for i in range(n):
        if sum(a[:i])<=x:res=i
print(max(0,res))
Buggy code:
N, x = map(int, input().split())
arr = sorted(list(map(int, input().split())))
ans = 0
for i in range(N):
    if x >= arr[i]:
        x -= arr[i]
        ans += 1
    else:
        break
print(max(ans,0))

Fixed code:
N, x = map(int, input().split())
arr = sorted(list(map(int, input().split())))
ans = 0
for i in range(N):
    if x >= arr[i]:
        x -= arr[i]
        ans += 1
    else:
        break
if ans == N and x != 0:
    ans -= 1
print(ans)
Buggy code:
# -*- coding: utf-8 -*-


#----------
n,x = list(map(int, input().rstrip().split()))
a_list = list(map(int, input().rstrip().split()))
#----------
a_list.sort()

x_remain=x
result = -1
for i in range(n):
    x_remain -= a_list[i]
    
    if x_remain < 0:
       result = i
       break

if result == -1 :
    result = n

print(result)


Fixed code:
# -*- coding: utf-8 -*-


#----------
n,x = list(map(int, input().rstrip().split()))
a_list = list(map(int, input().rstrip().split()))
#----------
a_list.sort()
x_remain=x

result = -1
for i in range(n):
    x_remain -= a_list[i]
    
    if x_remain == 0:
        result = i+1
        break
    if x_remain < 0:
        result = i
        break

if result == -1 :
    result = n-1

print(result)
Buggy code:
N,x = map(int, input().split())
A = sorted(map(int, input().split()))
s = 0
for i in range(N):
  x -= A[i]
  if x<0:
    break
  else:
    s += 1
print(s)

Fixed code:
N,x = map(int, input().split())
A = sorted(map(int, input().split()))
s = 0
for i in range(N):
  x -= A[i]
  if x<0:
    break
  else:
    s += 1
print(s if x<=0 else s-1)
Buggy code:
N, x =map(int, input().split())
a = sorted(map(int, input().split()))

i = 0
while (i<N) and (x>0):
    x -= a[i]
    i += 1

print(i)


Fixed code:
N, x =map(int, input().split())
a = sorted(map(int, input().split()))

i = 0

while (i<N) and (x>=0):
    x -= a[i]
    if x>=0:
        i += 1

if (i == N) and (x>0) :
    print(N-1)
else:
    print(i)
Buggy code:
import numpy as np

N, x = list(map(int, input().split()))
a = np.asarray(list(map(int, input().split())))
a = np.sort(a)
s = 0
for i in range(1, N):
    if np.sum(a[:i]) < x:
        s += 1
if np.sum(a) == x:
    s += 1
print(s)

Fixed code:
import numpy as np

N, x = list(map(int, input().split()))
a = np.asarray(list(map(int, input().split())))
a = np.sort(a)
s = 0
for i in range(1, N):
    if np.sum(a[:i]) <= x:
        s += 1
if np.sum(a) == x:
    s += 1
print(s)
Buggy code:
n,x = map(int,input().split())
l = sorted(list(map(int,input().split())))
pe = 0
for i in l:
  if x-i>=0:
    x -= i
    pe += 1
  else:
    break
if x!=0:
  print(pe-1)
else:
  print(pe)

Fixed code:
n,x = map(int,input().split())
l = sorted(list(map(int,input().split())))
pe = 0
for i in l:
  if x-i>=0:
    x -= i
    pe += 1
  else:
    break
if x!=0 and n==pe:
  print(pe-1)
else:
  print(pe)
Buggy code:
N, x = map(int, input().split(" "))
a = list(map(int, input().split(" ")))
children = [0] * N
a.sort()
kashi = 0
n = N
if a[0] > x:
    print(0)
elif sum(a) == x:
    print(N)
else:
    while kashi < x:
        for i in range(0,n):
            kashi += a[i]
            children[i] += 1
            if kashi > x:
                kashi -= a[i]
                children[i] -= 1
                break
#        print(kashi)
        n -= 1
        if n < 1:
            break
#    print(children)
    print(N - children.count(0))

Fixed code:
N, x = map(int, input().split(" "))
a = list(map(int, input().split(" ")))
children = [0] * N
a.sort()
kashi = 0
n = N
if a[0] > x:
    print(0)
elif sum(a) == x:
    print(N)
else:
    for i in range(0,n):
        if kashi > x:
            break        
        kashi += a[i]
        children[i] += 1
#     print(kashi)
    if kashi == x :
        print(N - children.count(0))
    else:
        print(N - children.count(0) - 1)
Buggy code:
N, x = map(int, input().split())
a = sorted(map(int, input().split()))
cnt = 0
for i in range(N):
  if a[i] < x:
    cnt += 1
    x -= a[i]
  else:
    break
if x > 0:
  cnt -= 1
print(cnt)

Fixed code:
N, x = map(int, input().split())
a = sorted(map(int, input().split()))
cnt = 0
for i in range(N):
  if a[i] <= x:
    cnt += 1
    x -= a[i]
  else:
    break
if cnt == N and x > 0:
  cnt -= 1
print(cnt)
Buggy code:
n,x =map(int, input().split())
a=sorted(list(map(int, input().split())))
cnt = 0
for r in a:
    if r<=x:
        cnt += 1
        x-=r
if x>0:
    cnt -= 1
print(cnt)

Fixed code:
n,x =map(int, input().split())
a=sorted(list(map(int, input().split())))
cnt = 0
for r in a:
    if r<=x:
        cnt += 1
        x-=r
        n -= 1
if x>0 and n==0:
    cnt -= 1
print(cnt)
Buggy code:
N,X = map(int,input().split(' '))
num_list = list(map(int,input().split(' ')))
num_list_s = sorted(num_list)
sum = 0
index = 0
for i in range(N):
    sum += num_list_s[i]
    if sum > X:
        break
    else:
        index += 1
print(index)
    

Fixed code:
N,X = map(int,input().split(' '))
num_list = list(map(int,input().split(' ')))
num_list_s = sorted(num_list)
total = 0
index = 0
for i in range(N):
    total += num_list_s[i]
    if total > X:
        break
    else:
        index += 1
if sum(num_list) < X:
    print(index-1)
else:
    print(index)
Buggy code:
N, x = list(map(int, input().split()))
A = list(map(int, input().split()))

#print(N, x)
A.sort()
#print(A)

cnt = 0
for a in A:
  if x >= a:
    x -= a
    cnt += 1
  else:
    break
      
print(cnt)
    

Fixed code:
N, x = list(map(int, input().split()))
A = list(map(int, input().split()))

#print(N, x)
A.sort()
#print(A)

cnt = 0
for a in A:
  if x >= a:
    x -= a
    cnt += 1
  
  else:
    break

if cnt == N and x > 0:
  cnt = cnt - 1
print(cnt)
Buggy code:
N, x = map(int, input().split())
a = list(map(int, input().split()))

a.sort()
max = 0
for i in range(1, N + 1):
  if sum(a[:i]) <= x:
    max = i
if sum(a[:N + 1]) <= x:
  print(N - 1)
else:
  print(max)

Fixed code:
N, x = map(int, input().split())
a = list(map(int, input().split()))

a.sort()
max = 0
for i in range(1, N + 1):
  if sum(a[:i]) <= x:
    max = i
if sum(a[:N + 1]) < x:
  print(N - 1)
else:
  print(max)
Buggy code:
N,x = map(int,input().split())
alist = list(map(int,input().split()))
alist.sort()
counter = 0
for i in range(N):
    x -= alist[i]
    if x>=0:
        if i!=N-1:
            counter += 1
    else:
        break
print(counter)


Fixed code:
N,x = map(int,input().split())
alist = list(map(int,input().split()))
alist.sort()
counter = 0
for i in range(N):
    x -= alist[i]
    if x>=0:
        if i!=N-1:
            counter += 1
        else:
            if x==0:
                counter += 1
    else:
        break
print(counter)
Buggy code:
N, x = map(int, input().split())
a = list(map(int, input().split()))
a = sorted(a)
n = 0
for i in range(N):
  x -= a[i]
  if x < 0:
    break
  n += 1
print(n)

Fixed code:
N, x = map(int, input().split())
a = list(map(int, input().split()))
a = sorted(a)
n = 0
for i in range(N):
  n += 1
  x -= a[i]
  if x < 0:
    break
if x != 0:
  n -= 1
print(n)
Buggy code:
N, x = map(int, input().split())
a = [int(i) for i in input().split()]
a.sort()
frag = False
count = 0
for i in range(len(a)):
    if x >= a[i]:
        count += 1
        x -= a[i]
    else:
        frag = True
        break
if not frag:
    count -= 1
print(count)


Fixed code:
N, x = map(int, input().split())
a = [int(i) for i in input().split()]
a.sort()
frag = False
count = 0
for i in range(len(a)):
    if x >= a[i]:
        count += 1
        x -= a[i]
    else:
        frag = True
        break
if not frag and x != 0:
    count -= 1
print(count)
Buggy code:
n, x = map(int, input().split())
a = list(map(int, input().split()))
a.sort()

count = 0
for ai in a:
	if x <= 0:
		break
	if x >= ai:
		x -= ai
		count += 1

print(count)

Fixed code:
n, x = map(int, input().split())
a = list(map(int, input().split()))
a.sort()

count = 0
for ai in a:
	if x >= 0 and x < ai:
		break
	else:
		x -= ai
		count += 1
else:
	if x > 0:
		count -= 1

print(count)
Buggy code:

def main():
    n, x = map(int,input().split())
    a = list(map(int,input().split()))

    a = sorted(a)
    ans = 0
    tmp = 0
    for i in a:
        tmp += i
        if tmp <= x:
            ans+=1

    print(ans)




if __name__ == "__main__":
        main()


Fixed code:

def main():
    n, x = map(int,input().split())
    a = list(map(int,input().split()))

    a = sorted(a)
    ans = 0
    tmp = 0
    for i in a:
        tmp += i
        if tmp <= x:
            ans+=1

    if n == ans:
        if sum(a) != x:
            ans-=1

    print(ans)




if __name__ == "__main__":
        main()
Buggy code:
n,x,*a=map(int, open(0).read().split())
a.sort()
for i in range(n):
    x-=a[i]
    if x<0:
      print(i)
      exit()
print(n)

Fixed code:
n,x,*a=map(int, open(0).read().split())
a.sort()
for i in range(n):
    x-=a[i]
    if x<0:
      print(i)
      exit()
    elif x==0:
      print(-~i)
      exit()
print(n-1)
Buggy code:
#Candy Distribution Again
n,x = map(int, input().split())
s= list(map(int,input().split()))

s.sort()
s.reverse
if s[0]>x:
    ans=1
else :
    ans=0
for i in s:
    x=x-i
    if x>=0:
        ans+=1
    else :
        break
if x!=0:
        ans-=1
print(ans)




Fixed code:
#Candy Distribution Again
n,x = map(int, input().split())
s= list(map(int,input().split()))

s.sort()
s.reverse
ans=0
if s[0]>x:
    print(ans)
else :
    for i in s:
        x=x-i
        if x>=0:
            ans+=1
        else :
            break
    if x>0:
        ans-=1
    print(ans)
Buggy code:
N, x = map(int,input().split())
a = list(map(int,input().split()))
a.sort()
count = 0
for i in range(N):
    x = x - a[i]
    if x >= 0:
        count += 1  

print(count)

Fixed code:
N, x = map(int,input().split())
a = list(map(int,input().split()))
a.sort()
count = 0
for i in range(N):
    x = x - a[i]
    if x < 0:
        break
    count += 1  
if x > 0:
    count -= 1
print(count)
Buggy code:
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = 1e10

#solve
def solve():
    n, x = LI()
    a = LI()
    a = itertools.accumulate(a)
    ans = 0
    for ai in a:
        if ai > x:
            break
        ans += 1
    print(ans)
    return


#main
if __name__ == '__main__':
    solve()


Fixed code:
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = 1e10

#solve
def solve():
    n, x = LI()
    a = LI()
    a.sort()
    ans = 0
    for ai in a:
        x -= ai
        if x < 0:
            print(ans)
            return
        ans += 1
    print(ans - (x != 0))
    return


#main
if __name__ == '__main__':
    solve()
Buggy code:
N, x = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
sum = 0
count = 0
while True:
  sum += a[0]
  if sum > x or len(a) == 0:
    break
  count += 1
  del a[0]
print(count)

Fixed code:
N, x = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
sum = 0
count = 0
while True:
  sum += a[0]
  if sum > x:
    break
  count += 1
  del a[0]
  if len(a) == 0:
    break
if x > sum:
  print(count-1)
else:
  print(count)
Buggy code:
n,x = map(int,input().split())
a = list(map(int,input().split()))
a = sorted(a)
ans = 0
cnt = 0
for i in range(n):
    if a[i]<=x:
        x-=a[i]
        cnt += 1
if x<0:
    cnt -= 1
print(max(0,cnt))

Fixed code:
n,x = map(int,input().split())
a = list(map(int,input().split()))
a = sorted(a)
ans = 0
cnt = 0
for i in range(n):
    if a[i]<=x:
        cnt += 1
    x-=a[i]
if x>0:
    cnt -= 1
print(max(0,cnt))
Buggy code:
N, x = map(int,input().split())
A = list(map(int,input().split()))

A.sort()
S = 0
c = 0
for i in A:
    if S + i <= x:
        S += i
        c += 1
    else:
        break
print(c)


Fixed code:
N, x = map(int,input().split())
A = list(map(int,input().split()))

A.sort()
S = 0
c = 0
if sum(A) < x:
    print(N-1)
else:
    for i in A:
        if S + i <= x:
            S += i
            c += 1
        else:
            break
    print(c)
Buggy code:
#-*-coding:utf-8-*-

def main():
    n, x = map(int, input().split())
    a_list = list(map(int, input().split()))
    a_list.sort()
    total = 0
    ans = 0
    for i in range(n):
        total += a_list[i]
        if total <= x:
            ans += 1
    print(ans)

if __name__ == '__main__':
    main()

Fixed code:
#-*-coding:utf-8-*-

def main():
    n, x = map(int, input().split())
    a_list = list(map(int, input().split()))
    a_list.sort()
    total = 0
    ans = 0
    for i in range(n):
        total += a_list[i]
        if total <= x:
            ans += 1
    if total < x:
        print(ans - 1)
    else:
        print(ans)

if __name__ == '__main__':
    main()
Buggy code:
N, x = map(int, input().split())
a = list(map(int, input().split()))
cnt = 0
a.sort()
for i in range(N):
    if a[i]<=x:
        x -= a[i]
        cnt += 1
    else:
        break
print(cnt)

Fixed code:
N, x = map(int, input().split())
a = list(map(int, input().split()))
cnt = 0
a.sort()
for i in range(N):
    if a[i]<=x:
        x -= a[i]
        cnt += 1
    else:
        break
if (x!=0)and(cnt==N):
    cnt -= 1
print(cnt)
Buggy code:
n,x = map(int, input().split())
a = list(map(int, input().split()))

a.sort()

for i in range(n):
  if a[i] == n:
    ans+=1
    break
  elif a[i] > n:
    break
  else:
    if i!=n(-1):
      ans+=1
      n-=a[i]
print(ans)
    

Fixed code:
n,x = map(int,input().split())
a = list(map(int,input().split()))
ans = 0
a.sort()
for i in range(n):
    if x >= a[i]:
        if i == n-1:
            if a[i] == x:ans+=1
        else:
            x -= a[i]
            ans +=1
    else:break
print(ans)
Buggy code:
n, k = map(int, input().split())
a = list(map(int, input().split()))

ans = 0
is_broken = False
for num in sorted(a):
    if num > k:
        break
        is_broken = True
    else:
        k -= num
        ans += 1
if k != 0 and ans >= 1 and is_broken:
    ans -= 1
print(ans)


Fixed code:
n, k = map(int, input().split())
a = list(map(int, input().split()))

ans = 0
is_broken = False
for num in sorted(a):
    if num > k:
        is_broken = True
        break
    else:
        k -= num
        ans += 1
if k != 0 and ans >= 1 and not is_broken:
    ans -= 1
print(ans)
Buggy code:
n, x = map(int, input().split())

lis = map(int, input().split())


count = 0
for i in sorted(lis):
    x -= i
    if x < 0:
        break
    count += 1

print(count)


Fixed code:
n, x = map(int, input().split())

lis = map(int, input().split())


count = 0
for i in sorted(lis):
    x -= i
    if x < 0:
        break
    count += 1

if x > 0:
    count -= 1

print(count)
Buggy code:
ri = lambda: list(map(int,input().split()))

n,x = ri()
a = sorted(ri())
ans = 0
c = 0
for i in a:
    c += i
    if c>x:
        break
    ans += 1
print(ans)

Fixed code:
ri = lambda: list(map(int,input().split()))

n,x = ri()
a = sorted(ri())
ans = 0
c = 0
for i in a:
    c += i
    if c>x:
        break
    ans += 1
if c<x: ans -= 1
print(ans)
Buggy code:
n, x = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
if x < a[0]:
    print(0)
else:
    for i in range(n):
        x = x - a[i]
        if x > 0:
            continue
        elif x == 0:
            print(i+1)
            break
        else:
            print(i-2)
            break
if x > 0 and x > a[0]:
    print(n-1)

Fixed code:
n, x = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
y = x
if y < a[0]:
    print(0)
else:
    for i in range(n):
        x = x - a[i]
        if x > 0:
            continue
        elif x == 0:
            print(i+1)
            break
        elif x < 0:
            print(i)
            break
if x > 0 and y > a[0]:
    print(n-1)
Buggy code:
n,x=map(int,input().split())
a=sorted(list(map(int,input().split())))
c,i=0,0
while(i<n and x>0):
  if a[i]<=x:
    x-=a[i]
    c+=1
    i+=1
  else:
    break
print(c)

Fixed code:
n,x=map(int,input().split())
a=sorted(list(map(int,input().split())))
c,i=0,0
while(i<n and x>0):
  if a[i]<=x:
    x-=a[i]
    c+=1
  else:
    break
  if i==n-1 and x!=0:
    c-=1
  i+=1
print(c)
Buggy code:
n, x = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
for i in range(n):
    x = x - a[i]
    if x >= 0:
        continue
    else:
        print(i)
        break
if x >= 0:
    print(i+1)

Fixed code:
n,x=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
cnt=0
for i in range(n):
  x-=a[i]
  if x >= 0:
    cnt+=1
  else:
    break
if x > 0:
  cnt-=1
print(cnt)
Buggy code:
n, x = map(int, input().split())
array = list(map(int, input().split()))

count = 0
array = sorted(array, reverse=True)
for i in range(n):
    x = x - array[i]
    if x >= 0:
        count += 1
    else:
        break
print(count)

Fixed code:
n, x = map(int, input().split())
array = list(map(int, input().split()))

count = 0
array = sorted(array)
for i in range(n):
    x = x - array[i]
    if x >= 0:
        count += 1
    else:
        break
if x > 0:
    count -= 1
print(count)
Buggy code:
N, x = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
sum = 0
ans = 0
for i,a in enumerate(A):
    sum += a

    if sum == x:
        ans = i + 1
        break
    elif sum > x:
        break
    ans = i + 1


print(ans)


Fixed code:
N, x = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
sum = 0
ans = 0
for i,a in enumerate(A):
    sum += a

    if sum == x:
        ans = i + 1
        break
    elif sum > x:
        break
    elif i + 1 == N and sum < x:
        ans = i
        break
    ans = i + 1


print(ans)
Buggy code:
import sys
input=sys.stdin.readline
from bisect import bisect_right
import itertools

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

A.sort()
Acum = list(itertools.accumulate(A))
print(Acum)
answer = bisect_right(Acum,X)
if answer == N:
    if Acum[-1] < X:
        answer -= 1
print(answer)


Fixed code:

import sys
input=sys.stdin.readline
from bisect import bisect_right
import itertools

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

A.sort()
Acum = list(itertools.accumulate(A))
answer = bisect_right(Acum,X)
if answer == N:
    if Acum[-1] < X:
        answer -= 1
print(answer)
Buggy code:
n,x=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
a.reverse()
ans=0
while x>0:
  if len(a)==0:
    break
  if a[-1]<=x:
    x-=a.pop()
    ans+=1
  else:
    break
print(ans)

Fixed code:
n,x=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
a.reverse()
ans=0
while x>0:
  if x==0:
    break
  elif len(a)==0:
    ans-=1
    break
  if a[-1]<=x:
    x-=a.pop()
    ans+=1
  else:
    break
print(ans)
Buggy code:
N, x = map(int, input().split())
a = list(map(int, input().split()))

a.sort()
ans = 0

for i, v in enumerate(a):
    if x == v or (i != N - 1 and x >= v):
        ans += 1
    #
#

print(ans)

Fixed code:
N, x = map(int, input().split())
a = list(map(int, input().split()))

a.sort()
ans = 0

for i, v in enumerate(a):
    if x == v or (i != N - 1 and x >= v):
        ans += 1
    #
    x -= v
#

print(ans)
Buggy code:
n,x = map(int,input().split())
a = list(map(int,input().split()))

if sum(a) ==x:
    print(n)
else:
    a.sort()
    for i in range(n):
        if x >= a[i]:
            ans += 1
            x -= a[i]
        else:
            break




print(ans-1)

Fixed code:
n,x = map(int,input().split())
a = list(map(int,input().split()))
a.sort()
count = 0
if sum(a) == x:
  print(n)
else:
  for i in range(n-1):
    if x >= a[i]:
      x = x - a[i]
      count += 1
    else:
      break
    
  print(count)
Buggy code:
n,x=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
ans=0
for i in range(n):
  if a[i]<=x:
    x=x-a[i]
    ans=ans+1
print(ans)


Fixed code:
n,x=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
ans=0
for i in range(n):
  if a[i]<=x:
    x=x-a[i]
    ans=ans+1
if ans==n and x>0:
  ans=ans-1
print(ans)