Problem:
Taro's Shopping Mammy decided to give Taro his first shopping experience.
Mammy tells him to choose any two items he wants from those
listed in the shopping catalogue,
but Taro cannot decide which two, as all the items look attractive.
Thus he plans to buy the pair of two items with
the highest price sum, not exceeding the amount Mammy allows.
As getting two of the same item is boring, he wants two different items. You are asked to help Taro select the two items.
The price list for all of the items is given.
Among pairs of two items in the list,
find the pair with the highest price sum
not exceeding the allowed amount,
and report the sum.
Taro is buying two items, not one, nor three, nor more.
Note that, two or more items in the list may be priced equally. Input The input consists of multiple datasets, each in the following format.  n  m  a 1  a 2 ... a n  A dataset consists of two lines.
In the first line, the number of items n and the maximum
payment allowed m are given. n is an integer satisfying 2 ≤ n ≤ 1000. m is an integer satisfying 2 ≤ m ≤ 2,000,000.
In the second line, prices of n items are given. a i (1 ≤ i ≤ n ) is the price
of the i -th item.
This value is an integer greater than or equal to 1 and
less than or equal to 1,000,000. The end of the input is indicated by a line containing two zeros.
The sum of n 's of all the datasets does not exceed 50,000. Output For each dataset, find the pair with the highest price sum
not exceeding the allowed amount m and output the sum in a line.
If the price sum of every pair of items exceeds m ,
output NONE instead. Sample Input 3 45
10 20 30
6 10
1 2 5 8 9 11
7 100
11 34 83 47 59 29 70
4 100
80 70 60 50
4 20
10 5 10 16
0 0 Output for the Sample Input 40
10
99
NONE
20

Solution (Python):
while True:
    n, m = map(int, input().strip().split())
    if n == 0:
        break
    a = sorted(list(map(int, input().strip().split())))
    ans = 0
    pos = n - 1
    for i in range(n):
        while pos > i and a[i] + a[pos] > m:
            pos -= 1
        if pos <= i:
            break
        ans = max(ans, a[i] + a[pos])
    print(ans if ans > 0 else 'NONE')

Solution (Python):
anslist = []

while True:
    n, m = map(int, input().split())
    if n == 0 and m == 0:
        break
    a = list(map(int, input().split()))

    ans = 0
    for i in range(n):
        for j in range(n):
            if i != j and a[i] + a[j] <= m:
                ans = max(ans, a[i] + a[j])

    if ans == 0:
        anslist.append("NONE")
    else:
        anslist.append(ans)

for i in anslist:
    print(i)

Solution (Python):
while True:
    n, m = map(int, raw_input().split())
 
    if n == 0 and m == 0:
        break
 
    a = map(int, raw_input().split())
 
    ans = -1
 
    for i in range(n-1):
        for j in range(i+1, n):
            if a[i] + a[j] <= m:
                ans = max(ans, a[i] + a[j])
 
    print "NONE" if ans == -1 else ans

Solution (Python):


n_list = []
m_list = []
a_list = []

while True:
    n, m = list(map(int, input().split(' ')))

    if n == 0 and m == 0:
        break

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

    n_list.append(n)
    m_list.append(m)
    a_list.append(a)


for n, m, a in zip(n_list, m_list, a_list):
    m_sum = 0
    for i in range(0, n):
        for j in range(i + 1, n):
            tmp = a[i] + a[j]
            if m_sum < tmp and tmp <= m:
                m_sum = tmp

    if m_sum > 0:
        print(m_sum)
    else:
        print('NONE')

Solution (Python):


n_list = []
m_list = []
a_list = []

while True:
    n, m = list(map(int, input().split(' ')))

    if n == 0 and m == 0:
        break

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

    n_list.append(n)
    m_list.append(m)
    a_list.append(a)


for n, m, a in zip(n_list, m_list, a_list):
    m_sum = 0
    for i in range(0, n):
        for j in range(i + 1, n):
            tmp = a[i] + a[j]
            if m_sum < tmp and tmp <= m:
                m_sum = tmp

    if m_sum > 0:
        print(m_sum)
    else:
        print('NONE')

Solution (Python):


n_list = []
m_list = []
a_list = []

while True:
    n, m = list(map(int, input().split(' ')))

    if n == 0 and m == 0:
        break

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

    n_list.append(n)
    m_list.append(m)
    a_list.append(a)


for n, m, a in zip(n_list, m_list, a_list):
    m_sum = 0
    for i in range(0, n):
        for j in range(i + 1, n):
            tmp = a[i] + a[j]
            if m_sum < tmp and tmp <= m:
                m_sum = tmp

    if m_sum > 0:
        print(m_sum)
    else:
        print('NONE')

Solution (Python):
while True:
    N, M = map(int, input().split())
    if N == 0 and M == 0:
        break
    A = list(map(int, input().split()))
    ans = 0
    for i in range(N):
        for j in range(N):
            if i == j:
                pass
            elif M >= A[i] + A[j]:
                ans = max(A[i] + A[j], ans)
    if ans == 0:
        print("NONE")
    else:
        print(ans)

Solution (Python):
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, input().split()))
def inpl_str(): return list(input().split())

while True:
    n,m = inpl()
    if m == 0:
        break
    else:
        aa = inpl()
        aa.sort()
        ans = -1
        for i in range(n):
            x = aa[i]
            for j in range(n):
                y = aa[j]
                if i == j or x+y > m:
                    continue
                ans = max(x+y,ans)
        if ans == -1:
            print('NONE')
        else:
            print(ans)

Solution (Python):
n, m = map(int, input().split())
while n != 0 and m != 0:
    a = list(map(int, input().split()))
    dp = []
    for i in range(n):
        for j in range(n):
            if a[i]+a[j]<= m and i != j:
                dp.append(a[i]+a[j])
    if len(dp) == 0:
        print("NONE")
    else:
        print(max(dp))
    n, m = map(int, input().split())

Solution (Python):
while 1:
    n, m = map(int, input().split())
    if n == m == 0:
        break
    *A,=map(int, input().split())
    s=0
    for i in range(n):
        for j in range(i):
            if s<A[i]+A[j]<=m:
                s = A[i]+A[j]
    print(s or"NONE")

Solution (Python):
while 1:
    n, m = map(int, input().split())
    if n == m == 0:
        break
    A=sorted(map(int, input().split()))
    def f():
        j = n-1
        yield 0
        for i in range(n):
            while j >= 0 and m < A[i]+A[j]:
                j -= 1
            if j <= i:
                break
            if j >= 0:
                yield A[i]+A[j]
    print(max(f()) or"NONE")

Solution (Python):


import itertools


def rdp_connect() -> bool:
    global n, m, a
    n, m = map(int, input().split())
    if n == 0 and m == 0:
        return False
    a = list(map(int, input().split()))
    return True


if __name__ == '__main__':
    while rdp_connect():
        lis = filter(lambda e: e <= m, map(sum, itertools.combinations(a, 2)))
        try:
            print(max(lis))
        except ValueError:
            print('NONE')

Solution (Python):
while True:
	n, m = [int(i) for i in input().split()]
	if (n == 0) & (m == 0):
		break
	a = [int (i) for i in input().split()]
	ans = 0
	for i in range(n):
		for j in range(n):
			if i == j:
				continue
			if (a[i] + a[j] <= m) & (a[i] + a[j] > ans):
				ans = a[i] + a[j]

	if ans == 0:
		print('NONE')
	else:
		print(ans)

Solution (Python):
while True:
    (n,m) = map(int,input().split())
    if n == 0 and m == 0:
        break
    iss = list(map(int, input().split()))
    best = max([ (iss[i] + iss[j] if not ( i == j) and iss[i] + iss[j] <= m else -1) for i in range(0,n) for j in range(0,n) ])
    if(best < 0):
        print("NONE")
    else:
        print(best)

Solution (Python):
while True:
    (n,m) = map(int,input().split())
    if n == 0 and m == 0:
        break
    iss = list(map(int, input().split()))
    best = max([ (iss[i] + iss[j] if not ( i == j) and iss[i] + iss[j] <= m else -1) for i in range(0,n) for j in range(0,n) ])
    if(best < 0):
        print("NONE")
    else:
        print(best)

Solution (Python):
while True:
    n, m = map(int, raw_input().split())

    if n == 0 and m == 0:
        break

    s = map(int, raw_input().split())
    ans = -1

    for i in range(n):
        for j in range(i+1, n):
            if s[i] + s[j] <= m:
                ans = max(ans, s[i] + s[j]);

    print "NONE" if ans == -1 else ans

Solution (Python):
import bisect
while True:
    n, m = map(int, input().split())
    if n == 0:
        break
    a = list(map(int, input().split()))
    a.sort()
    p = 0
    for i in range(n - 1):
        x = bisect.bisect(a, m - a[i], i + 2)
        if a[x - 1] + a[i] <= m:
            p = max(p, a[x - 1] + a[i])
            if p == m:
                break
    if p:
        print(p)
    else:
        print("NONE")

Solution (Python):
import itertools as it

ans=[]

while 1:
    n,m=map(int,input().split())
    if n==0 and m==0:
        break
    A=list(map(int,input().split()))
    Ac=list(it.combinations(A,2))
    
    max=0
    flag=0

    for i in Ac:
        if sum(i)>=max and sum(i)<=m:
            max=sum(i)
            flag=1
        
    if flag==0:
        print("NONE")
    else:
        print(max)

Solution (Python):
while(1) :
    x = input().split()
    n = int(x[0])
    m = int(x[1])
    if (n == 0 and m == 0): break
    a = input().split()
    mx = -1
    for i in range(n-1):
        for j in range(i+1,n):
            tmp = int(a[i]) + int(a[j])
            if tmp > mx and tmp <= m: mx = tmp
    if mx == -1: print("NONE")
    else: print(mx)

Solution (Python):
while 1 :
    x = input().split()
    n = int(x[0])
    m = int(x[1])
    if n == 0 and m == 0: break
    a = input().split()
    mx = -1
    for i in range(n-1):
        for j in range(i+1,n):
            tmp = int(a[i]) + int(a[j])
            if tmp > mx and tmp <= m: mx = tmp
    if mx == -1: print("NONE")
    else: print(mx)

Solution (Python):
st = []
while 1:
    n,m = list(map(int, input().split()))
    max = -1
    if n==0:
        break
    
    a = list(map(int, input().split()))
    
    for i in range(len(a)):
        for j in range(i+1,len(a)):
            sum = a[i]+a[j]
            if sum<=m:
                if sum>max:
                    max = sum
    
    if max==-1:
        st.append("NONE")
    else:
        st.append(max)
            
for i in range(len(st)):
    print(st[i])

Solution (Python):
A=[0 for i in range(2)]
A=input().split()
n=int(A[0])
m=int(A[1])
max=[]
k=0
while n>0 and m>0:
    B=[0 for i in range(n)]
    B=input().split()
    for i in range(n):
        B[i]=int(B[i])
    ma=0
    for i in range(n):
        for j in range(i+1,n):  
            x=0 
            x=B[i]+B[j]
            if ma<x and x<=m:
                ma=x
    max.append(ma)
    A=input().split()
    n=int(A[0])
    m=int(A[1])
    k+=1
for i in range(k):
    if max[i]>0:
        print(max[i])
    else:
        print("NONE")

Solution (Python):
import itertools

while 1:
    A = input().split()

    n = int(A[0])
    if n == 0:
        break
    m = int(A[1])
    C = [int(i) for i in input().split()]
    comb = itertools.combinations(C, 2)
    rsl = 0
    flg = 0
    for i in comb:
        tmp = i[0] + i[1]
        if tmp <= m and tmp > rsl:
            rsl = tmp
            flg = 1

    if flg == 0: print("NONE")
    else: print(rsl)

Solution (Python):
maxes=[]
cnt=0
while True:
    s=input()
    d=s.split()
    n=int(d[0])
    m=int(d[1])
    if n==0 and m==0:
        break

    s=input()
    d=s.split()
    a=[]
    
    for i in range(n):
        a.append(int(d[i]))

    p=[[0 for i in range(n)] for j in range(n)]
    for i in range(n):
        for j in range(i+1,n):
            p[i][j]=(a[i]+a[j])


    max=0
    for i in range(n):
        for j in range(i+1,n):
            if p[i][j]>m:
                continue
            if max<p[i][j]:
                max=p[i][j]
    if max==0:
        maxes.append(-1)
    else:
        maxes.append(max)
    cnt+=1

for i in range(cnt):
    if maxes[i]==-1:
        print("NONE")
    else:
        print(maxes[i])

Solution (Python):
import itertools
a=input().split()
cnt=0
ans=[]
while(True):
    a=[int(i) for i in a]
    b=input().split()
    b=[int(i) for i in b]
    c=list(itertools.combinations(b,2))
    for i in range(len(c)):
        if cnt<=c[i][0]+c[i][1] and c[i][0]+c[i][1]<=a[1]:
            cnt=c[i][0]+c[i][1]
    if cnt==0:
      ans.append("NONE")
    else:
      ans.append(cnt)
    a=input().split()
    if(a[0]=='0' and a[1]=='0'):
      break
    cnt=0
for i in range(len(ans)):
  print(ans[i])

Solution (Python):
import itertools
a=input().split()
cnt=0
ans=[]
while(True):
    a=[int(i) for i in a]
    b=input().split()
    b=[int(i) for i in b]
    c=list(itertools.combinations(b,2))
    for i in range(len(c)):
        if cnt<=c[i][0]+c[i][1] and c[i][0]+c[i][1]<=a[1]:
            cnt=c[i][0]+c[i][1]
    if cnt==0:
      ans.append("NONE")
    else:
      ans.append(cnt)
    a=input().split()
    if(a[0]=='0' and a[1]=='0'):
      break
    cnt=0
for i in range(len(ans)):
  print(ans[i])

Solution (Python):
B=[]

while 1:
    n,m=map(int,input().split())
    if n==0 and m==0:
        break
    A=list(map(int,input().split()))
    A.sort()
    max=0
    for i in range(n):
        if A[i]>m:
            break
        for j in range(i+1,n):
            sum=A[i]+A[j]
            if sum>m:
                break
            elif sum>max:
                max=sum

    if max==0:
        B.append("NONE")
    else:
        B.append(max)

for b in B:
    print(b)

Solution (Python):
while 1:
    str=input().split()
    n=int(str[0])
    m=int(str[1])
    if n==0 and m==0: break
    str=input().split()
    a=[0]*n
    for i in range(n):
        a[i]=int(str[i])
    a.sort()
    a.reverse()
    flag=0
    max=0
    for i in range(n):
        if flag!=0: break
        for j in range(i+1,n):
            v=a[i]+a[j]
            if m>=v:
                if max<v: max=v
    if max==0: print("NONE")
    else: print(max)

Solution (Python):

s=[]

cnt=0

while 1:
    max=0
    n,m =map(int,input().split())
    if n==0 and m==0:
        break
    l=list(map(int,input().split()))


    for i in range(len(l)):
        for j in range(len(l)):
            if max<l[i]+l[j] and i!=j and m>=l[i]+l[j]:
                max=l[i]+l[j]

    if max==0:
        s+=["NONE"]
    else:
        s+=[max]


for x in s:
    print(x)

Solution (Python):
maxs=[]
while(True):
    max=-1
    
    b=list(map(int,input().split()))
    n=b[0]
    m=b[1]
    if(n == 0 and m == 0):
        break
    a=list(map(int,input().split()))
    for i in range(n):
        for j in range(i+1,n):
            sum=a[i]+a[j]
            if(sum>max and sum<=m):
                max=sum
    maxs.append(max)

for i in maxs:
    if i==-1:
        print("NONE")
    else:
        print(i)

Solution (Python):
ans = []
cou = 0

while(1):
    n,m = map(int,input().split())
    if(n == 0): break
    ar = list(map(int,input().split()))
    max_ans = 0


    for i in range(n-1):
        for j in range(i+1,n):
            if(max_ans < ar[i]+ar[j] and ar[i]+ar[j] <= m):
                max_ans = ar[i] + ar[j]

    ans.append(max_ans)
    cou += 1

for i in range(cou):
    if(ans[i] == 0): print("NONE")
    else: print(ans[i])

Solution (Python):
while 1!=0:
    n, m = map(int,input().split())
    if n==0 and m==0:
        break
    lista= [int (i) for i in input().split()]
    ans = 0
    for i in range(n):
        for j in range(n):
            if i == j:
                continue
            if (lista[i]+lista[j])<=m and (lista[i]+lista[j])>ans:
                ans = lista[i] + lista[j]
                
    if ans == 0:
        print('NONE')
    else:
        print(ans)

Solution (Python):
C=[0 for i in range(2)]
C=input().split()
n=(int)(C[0])
x=(int)(C[1])

B=[]
cnt=0
while n>0:

	A=[0 for i in range(n)]
	A=input().split()

	max=0

	for i in range(len(A)-1):
		for j in range(i+1, len(A)):
			if max<(int)(A[i])+(int)(A[j]) and (int)(A[i])+(int)(A[j])<=x:
				max=(int)(A[i])+(int)(A[j])
	if max>0:
		B.append(max)
	else:
		B.append("NONE")

	C=[0 for i in range(2)]
	C=input().split()
	n=(int)(C[0])
	x=(int)(C[1])

	cnt+=1

for i in range(cnt):
	print(B[i])

Solution (Python):
price = []
while 1:
    a = []
    n,m = map(int,input().split())
    if n == 0 and m == 0:
        break
    a = list(map(int,input().split()))
    a.sort(reverse=True)
    sum = -1
    for i in range(len(a)-1):
        for j in range(i+1,len(a)):
            if a[i] + a[j] <= m and sum <= a[i] + a[j]:
                sum = a[i] + a[j]
    if sum < 0:
        price.append(-1)
    else:
        price.append(sum)

for i in range(len(price)):
    if price[i] >= 0:
        print(price[i])
    else:
        print('NONE')

Solution (Python):
price = []
while 1:
    a = []
    n,m = map(int,input().split())
    if n == 0 and m == 0:
        break
    a = list(map(int,input().split()))
    a.sort(reverse=True)
    sum = -1
    for i in range(len(a)-1):
        for j in range(i+1,len(a)):
            if a[i] + a[j] <= m and sum <= a[i] + a[j]:
                sum = a[i] + a[j]
    if sum < 0:
        price.append(-1)
    else:
        price.append(sum)

for i in range(len(price)):
    if price[i] >= 0:
        print(price[i])
    else:
        print('NONE')

Solution (Python):
ans=[]
n,m=map(int,input().split())
while n!=0 and m!=0:
    a=[0]*n
    a=list(input().split())
    for i in range(n):
        a[i]=int(a[i])
    max=0
    for i in range(n):
        for j in range(n):
            if i<j:
                tmp=a[i]+a[j]
                if tmp>max and tmp<=m:
                    max=tmp
                else: pass
            else: pass
    ans.append(max)
    n,m=map(int,input().split())
for i in range(len(ans)):
    if ans[i]==0:
        print("NONE")
    else:
        print(ans[i])

Solution (Python):
n,m=input().split()
n=(int)(n)
m=(int)(m)


B=[]
cnt=0
while n!=0 and m!=0:
    A=input().split()
    cnt=0
    max=0
    for i in range(n):
        A[i]=(int)(A[i])
    for i in range(n):
        for j in range(i+1,n):
            x=A[i]+A[j]
            if x>max and x<=m:
                max=x
    if max>0:
        B.append(max)
    else:
        B.append('NONE')
    cnt+=1
    n,m=input().split()
    n=(int)(n)
    m=(int)(m)

for i in range(len(B)):
    print(B[i])

Solution (Python):
A=[0 for i in range(2)]
A=input().split()
n=int(A[0])
m=int(A[1])


max=[]
k=0
while n>0 and m>0:
    B=[0 for i in range(n)]
    B=input().split()
    for i in range(n):
        B[i]=int(B[i])
    ma=0
    for i in range(n):
        for j in range(i+1,n):  
            x=0 
            x=B[i]+B[j]
            if ma<x and x<=m:
                ma=x
    max.append(ma)
    A=input().split()
    n=int(A[0])
    m=int(A[1])
    k+=1
for i in range(k):
    if max[i]>0:
        print(max[i])
    else:
        print("NONE")

Solution (Python):
A=[0 for i in range(2)]
A=input().split()
n=int(A[0])
m=int(A[1])
max=[]
k=0

while n>0 and m>0:
    B=[0 for i in range(n)]
    B=input().split()
    for i in range(n):
        B[i]=int(B[i])
    max1=0
    for i in range(n):
        for j in range(i+1,n):  
            x=0 
            x=B[i]+B[j]
            if max1<x and x<=m:
                max1=x
    max.append(max1)
    A=input().split()
    n=int(A[0])
    m=int(A[1])
    k+=1
for i in range(k):
    if max[i]>0:
        print(max[i])
    else:
        print("NONE")

Solution (Python):
A=[]
while(True):
	n,m=map(int,input().split())
	if n==0 and m==0:
		break
	
	P=list(map(int,input().split()))
	
	mark=1
	sign=1
	for i in range(n):
		for j in range(i,n):
			if i==j:
				pass
			else:
				
				if m-(P[i]+P[j])>=0:
					if mark==1:
						max=P[i]+P[j]
						mark=0
						sign=0
					else:
						if P[i]+P[j]>max:
							max=P[i]+P[j]
				else:
					pass
	if sign==0:
		A.append(max)
	else:
		A.append(-1)

A.reverse()
for i in range(len(A)):
	tmp=A.pop()
	if tmp==-1:
		print("NONE")
	else:
		print(tmp)

Solution (Python):
n=5
m=5
z=0
sum=0
A=[]

while n!=0:
    n,m=[int(i) for i in input().split()]
    if n==0 and m==0:
        break
    val=[int(i) for i in input().split()]
    ans1=0
    mm=0
    for i in range(0,n):
        for j in range(i+1,n):
            if i==j:
                break
            ans1=val[i]+val[j]
            if ans1>mm and ans1<=m:
                mm=ans1
        ans1=0
    A.append(mm)
    z=z+1

for i in range(z):
    if A[i]==0:
        A[i]="NONE"
    print(A[i])

Solution (Python):
while True:
	n,m = map(int,input().split())
	if n == 0 and m == 0:	
		break
	a = list(map(int,input().split()))
	a.sort()
	list1 = []
	for i in range(n):
		for j in range(i + 1, n):
		 	price1 = a[i] + a[j]
		 	list1.append(price1)
	list1.sort()
	list2 = list(filter(lambda p: m >= p, list1))


	if list2:
		print(max(list2))
	else:
		print("NONE")

Solution (Python):
import sys
while(True):
    items=[]
    max=0
    n, m = map(int, input().split())
    if (n == 0 & m == 0):exit()
    items = list(map(int, input().split()))
    for i in range(n):
        for j in range(n):
            sum = items[i] + items[j]
            if (i != j and sum <= m and sum > max):
                max = sum
    if (max == 0):
        print("NONE")
    else:
        print(max)

Solution (Python):
def Price_combination():
    combination = []
    for i, x in enumerate(a):
        j = i + 1
        for y in a[j:]:
            if x + y <= m:
                combination.append(x+y)

    return combination

while True:
    n, m = map(int, input().split())
    if n == m == 0:
        break

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

    
    combination = Price_combination()
    

    if len(combination):
        print(max(combination))
    else:
        print("NONE")

Solution (Python):
while True:
    n, m = map(int, raw_input().split())

    if n == 0 and m == 0:
        break

    a = map(int, raw_input().split())

    ans = -1

    for i in range(n-1):
        for j in range(i+1, n):
            if a[i] + a[j] <= m:
                ans = max(ans, a[i] + a[j])

    print "NONE" if ans == -1 else ans

Solution (Python):
while True:
    t = 0
    n,m = map(int,input().split())
    if n != 0:
        a = list(map(int,input().split()))
        a.sort(reverse=True)
        for i in range(n - 1):
            k = a[i]
            for j in range(n - i - 1):
                if k + a[i+j+1] <= m:
                    if k + a[i+j+1] >= t:
                        t = k + a[i+j+1]
                    break
        if t == 0:
            print("NONE")
        else:
            print(t)
    else:
        break

Solution (Python):
while True:
    (n, m) = tuple(map(int, input().split()))
    if n == 0:
        break
    arr = list(map(int, input().split()))
    arr.sort()
    
    res = -1
    for i, e in enumerate(arr[:-1]):
        d = i + 1
        if e + arr[i + 1] > m:
            break
        u = n
        while u - d > 1:
            medi = int((u + d) / 2)
            if e + arr[medi] > m:
                u = medi
            else:
                d = medi
        res = max(res, e + arr[d])
    if res < 0:
        print("NONE")
    else:
        print(res)

Solution (Python):
while True:
    n,m=[int(i) for i in input().split()]
    if n==0:
        break 
    a = [int(i) for i in input().split()]

    ans  = -1
    for i in range(n):
        for j in range(i+1,n):
            if a[i]+a[j] <= m:
                ans =max(a[i]+a[j] ,ans)
    if ans ==-1:
        print("NONE")
    else:
        print(ans)

Solution (Python):
while True:
    S=[]
    n,m=map(int,input().split())
    if n==0 and m==0:
        break
    else:
        a=list(map(int,input().split()))
        a.sort(reverse=True)
        ans="NONE"
        for i in range(n-1):
            for j in range(i+1,n):
                s=a[i]+a[j]
                S.append(s)
        S.sort(reverse=True)
        for k in range (len(S)):
            if S[k]<=m:
                ans=S[k]
                break
            else:
                pass
        print(ans)

Solution (Python):
while True:
    n,m = map(int,input().split())
    if n==0:
      break
    a = list(map(int,input().split()))
    lst = []
    for i in range(n-1):
        for j in range(i+1, n):
            if a[i]+a[j] <= m:
                lst.append(a[i]+a[j])
    if len(lst) == 0:
        print('NONE')
    else:
        print(max(lst))

Solution (Python):
while True:
    n,m=map(int,input().split())
    if n==m==0:
        break
    cata=list(map(int,input().split()))
    max=0
    sum=0
    for i in range(n):
        for j in range(i+1,n):
            sum=cata[i]+cata[j]
            if sum<=m and sum>max:
                max=sum
    if max==0:
        print('NONE')
    else:
        print(max)

Solution (Python):
while True:
    n,m = map(int,input().split());
    if n == 0 and m == 0:
        break;
    B = list(map(int, input().split()));

    sum = 0;
    for i in range(0,n):
        for j in range(0,n):
            if i != j:
                if m >= B[i]+B[j]:
                    if sum <= B[i]+B[j]:
                        sum = B[i]+B[j];

    if sum == 0:
        print("NONE");
    else:
        print(sum);

Solution (Python):
while True:
	s,t = map(int,input().split())
	if s == 0 and t == 0:	
		break
	a = list(map(int,input().split()))
	a.sort()
	list1 = []
	for i in range(s):
		for j in range(i + 1, s):
		 	price1 = a[i] + a[j]
		 	list1.append(price1)
	list1.sort()
	list2 = list(filter(lambda p: t >= p, list1))


	if list2:
		print(max(list2))
	else:
		print("NONE")

Solution (Python):
while True:
    n,m=map(int, input().split())
    if n==0 and m==0:
        break
    a=list(map(int, input().split()))
    
    price=0
    for i in range(n-1):
        for j in range(i+1, n):
            if i==j:
                break
            
            if a[i]+a[j]>price and a[i]+a[j]<=m:
                price=a[i]+a[j]
                
    if price==0:
        print("NONE")
    else:
        print(price)

Solution (Python):
while True:
    n, m = map(int, input().split())
    
    if n == m == 0:
        break
    
    else:
        a = list(map(int, input().split()))
        
        ans = 0
        for i in range(n):
            for j in range(1, n):
                if i != j:
                    kau = a[i] + a[j]
                    if kau <= m and kau > ans:
                        ans = kau
        
        if ans == 0:
            print('NONE')
        else:
            print(ans)

Solution (Python):
while True:
    n,m = map(int,input().split())
    if n == 0 and m == 0:
        break
    a = list(map(int,input().split()))
    
    b = 0
    for i in range(n):
        for j in range(i+1,n):
            if m < a[i] + a[j]:
                continue
            b = max(b,a[i] + a[j])
    if b == 0:
        print("NONE")
    else:
        print(b)

Solution (Python):
while 1:
    n,m=map(int,input().split())
    if n==m==0:
        break
    A=sorted(map(int,input().split()))
    def f():
        j=n-1
        yield 0
        for i in range(n):
            while j >=0 and m<A[i]+A[j]:
                j-=1
            if j <=i:
                break
            if j >=0:
                yield A[i]+A[j]
    print(max(f())or"NONE")

Solution (Python):
while True:
    n,m=map(int,input().split())
    A=[]
    a=[]
    V=0
    if n==0 and m==0:
        break
    A=list(map(int,input().split()))
    for i in range(n-1):
        for j in range(n-i-1):
            B=0
            B=A[i]+A[i+j+1]
            if B<=m:
                a.append(B)
                V=1
    if V==0:
        print('NONE')
    else:
        print(max(a))

Solution (Python):
while True:
    n, m = map(int, input().split())
    if m == 0 and n == 0:
        break
    a = list(map(int, input().split()))
    ans = 0
    for i in range(n - 1):
        for j in range(i + 1, n):
            if m >= a[i] + a[j]:
                ans = max(ans, a[i] + a[j])
    if ans == 0:
        print("NONE")
    else:
        print(ans)

Solution (Python):
while True:
   n,m = map(int, input().split())
   if n==0 and m==0:
      break
   a = list(map(int, input().split()))
   s = []
   for p in range(n):
      for q in range(n):
         if p >= q:
            pass
         else:
            if a[p] + a[q] <= m:
               s.append(a[p] + a[q])
   s.sort()
   if s == []:
      print('NONE')
   else:
      print(s[len(s)-1])

Solution (Python):
while True:
    n,m=map(int,input().split())
    if n==0 and m==0:
        break
    else:
        s=sorted(list(map(int,input().split())))
        ans=0
        for i in range(n):
            for j in reversed(range(i+1,n)):
                if s[i]+s[j]>m:
                    continue
                else:
                    ans=max(ans,s[i]+s[j])
                    break
        if ans==0:
            print("NONE")
        else:
            print(ans)

Solution (Python):
import bisect

while True:
    n, m = map(int, input().split())
    if n == 0:
        break
    a = sorted(map(int, input().split()))
    index = bisect.bisect_left(a, m) - 1
    if index <= 0:
        print("NONE")
        continue
    ans = 0
    for i in range(index, 0, -1):
        for j in range(i-1, -1, -1):
            if a[i] + a[j] <= m:
                ans = max(ans, a[i] + a[j])
    if ans:
        print(ans)
    else:
        print("NONE")

Solution (Python):
import sys

def main(N,M,A):
    ans = []
    for i in range(N-1):
        for j in range(i+1,N):
            if A[i]+A[j] <= M:
                ans.append(A[i]+A[j])
    return max(ans) if ans else 'NONE'

while 1:
    N,M = [int(x) for x in sys.stdin.readline().split()]
    if N==M==0:
        break
    A = [int(x) for x in sys.stdin.readline().split()]
    print(main(N,M,A))

Solution (Python):

while True:
    n,m = map(int,input().split())
    if n==m==0: break
    price = list(map(int,input().split()))
    mx = 0
    
    for i in range(n-1):
        for j in range(i+1,n):
            if mx<price[i]+price[j]<=m:
                mx = price[i]+price[j]
    
    if mx==0: print("NONE")
    else: print(mx)

Solution (Python):
while True:
    n,m = map(int,input().split())
    if n==0 and m==0:
        break
    maxz = 0
    a = input().split()
    l = list(map(int,a))
    b = 0
    
    for i in range(n):
        for j in range(n):
            if i == j:
                continue
            if l[i]+l[j] <= m and  maxz < l[i]+l[j]:                    
                maxz = l[i]+l[j]
        
    if maxz ==  0:
        print("NONE")
    else:
        print(maxz)

Solution (Python):



while True:
   n, m = map(int, input().split())   
   if n + m == 0: break

   price = list(map(int, input().split()))
   
   
   sum = 0
   max = 0
   c = 0
   for i in range(n):
      for j in range(i + 1, n):
         sum = price[i] + price[j]
         if sum <= m and sum > max:
            max = sum
            
   if max == 0:
      print("NONE")
   else:
      print(max)

Solution (Python):
while True:
    n,m=map(int,input().split())
    if n==0:
        break
    nmax=0
    a=list(map(int,input().split()))
    for i in range(n):
        for j in range(i+1,n):
            sum=a[i]+a[j]
            if nmax<sum<=m:
                nmax=sum
    if nmax==0:
        print("NONE")
    else :
        print(nmax)

Solution (Python):
while True:
    n, m = map(int, input().split())
    if n == 0 and m == 0:
        exit()
    A = list(map(int, input().split()))
    ans = 0
    for i in range(n - 1):
        for j in range(i + 1, n):
            if ans < A[i] + A[j] <= m:
                ans = A[i] + A[j]
    print(ans if ans != 0 else 'NONE')