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
a1 a2 ... an

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 &#8804; n &#8804; 1000.
m is an integer satisfying 2 &#8804; m &#8804; 2,000,000.
In the second line, prices of n items are given.
ai (1 &#8804; i &#8804; 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



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


Sample output:
40
10
99
NONE
20

Submission status: Wrong Answer

Solution code:
while(True):
    n,m=map(int,input().split(" "))
    if(n==0):
        break
    things = set(map(int,input().split(" ")))
    _max=0
    for i in things:
        for j in things:
            if(i!=j and i+j < m and i+j>_max):
                _max = i+j
    print(_max)

Submission status: Wrong Answer

Solution code:
while(True):
    n,m=map(int,input().split(" "))
    if(n==0):
        break
    things = set(map(int,input().split(" ")))
    _max=0
    for i in things:
        for j in things:
            if(i!=j and i+j < m and i+j>_max):
                _max = i+j
    if _max != None:
        print(_max)
    else:
        print("NONE")

Submission status: Wrong Answer

Solution code:
while(True):
    n,m=map(int,input().split(" "))
    if(n==0):
        break
    things = set(map(int,input().split(" ")))
    _max=0
    for i in things:
        for j in things:
            if(i!=j and i+j <= m and i+j>_max):
                _max = i+j
    if _max != None:
        print(_max)
    else:
        print("NONE")

Submission status: Wrong Answer

Solution code:
while(True):
    n,m=map(int,input().split(" "))
    if(n==0):
        break
    things = list(map(int,input().split(" ")))
    _max=0
    for i in range(len(things)):
        for j in range(i+1,len(things)):
            if things[ i]+things[j] <= m:
                _max = max(things[i]+things[j],_max)
    if _max != None:
        print(_max)
    else:
        print("NONE")

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3

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')

Submission status: Wrong Answer

Solution code:
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 and m < A[i]+A[j]:
                j -= 1
            if j:
                yield A[i] + A[j]
    print(max(f()) or"NONE")

Submission status: Wrong Answer

Solution code:
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 >= 0:
                yield A[i] + A[j]
    print(max(f()) or"NONE")

Submission status: Wrong Answer

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

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

max=(int)(A[0])+(int)(A[1])

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])

print(max)

Submission status: Wrong Answer

Solution code:
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-1):
        for j in range(i,n):   
            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")

Submission status: Wrong Answer

Solution code:
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,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])

Submission status: Wrong Answer

Solution code:
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):
        if int(d[i]) in a:
            n-=1
        else:
            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])

Submission status: Wrong Answer

Solution code:
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,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])

Submission status: Wrong Answer

Solution code:
#16D8101014F 久留米 竜之介 2018/5/16 Python3 

Box=[]
Box2=[]
tmp=[]
mon=0
while True:
	Sum=0
	mon=0
	n,m=map(int,input().split())
	if n==0: break
	tmp=input().split()
	#print(tmp)
	for i in range(n):
		Box.append(int(tmp[i]))
	for j in range(n):
		for k in range(n):
			if j is not k:
				mon=Box[j]+Box[k]
			if mon <= m and Sum < mon:
				Sum=mon
	if Sum is not 0:
		Box2.append(Sum)				
	else:
		Box2.append("NONE")
	Box.clear()
	
for i in Box2:
	print(i)

Submission status: Wrong Answer

Solution code:
#16D8101014F 久留米 竜之介 2018/5/16 Python3 

Box=[]
Box2=[]
tmp=[]
mon=0
while True:
	Sum=0
	mon=0
	n,m=map(int,input().split())
	if n==0: break
	tmp=input().split()
	#print(tmp)
	for i in range(n):
		Box.append(int(tmp[i]))
	for j in range(n):
		for k in range(n):
			if j is not k:
				mon=Box[j]+Box[k]
			if mon <= m and Sum < mon:
				Sum=mon
	if Sum is not 0:
		Box2.append(Sum)				
	else:
		Box2.append("NONE")
	Box.clear()
	
for i in Box2:
	print(i)

Submission status: Wrong Answer

Solution code:

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,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])

Submission status: Wrong Answer

Solution code:
while(True):
    max=0
    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
    if m==0:
        print("NONE")
    else:
        print(max)

Submission status: Wrong Answer

Solution code:
ans = []
cou = 0

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


    for i in range(n-1):
        for j in range(i,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])

Submission status: Wrong Answer

Solution code:
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()
    print(a)
    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)

Submission status: Wrong Answer

Solution code:
maxs=[]
while(True):
    max=0
    
    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==0:
        print("NONE")
    else:
        print(i)

Submission status: Wrong Answer

Solution code:
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)

Submission status: Wrong Answer

Solution code:
s=[]
cnt=0
while 1:
    n,m=map(int,input().split())

    if n==0 and m==0:
        break
    a=list(int(i) for i in input().split())
    max=0

    for i in range(n):
     for j in range(1,n-1):
        c=a[i]+a[j]
        if max<=c and c<=m:
            max=c    
    if max==0:
        s.append(0)
    else: 
        s.append(max)
    a=[0]
    cnt=cnt+1

for i in range(cnt):
    if s[i]==0:
        print("none")
    else:
        print(s[i])

Submission status: Wrong Answer

Solution code:
#16D8102008K Taro'sShopping Yagyu Hazuki
s=[]
cnt=0
while 1:
    n,m=map(int,input().split())

    if n==0 and m==0:
        break
    a=list(int(i) for i in input().split())
    max=0

    for i in range(n):
     for j in range(1,n-1):
        c=a[i]+a[j]
        if max<=c and c<=m:
            max=c    
    if max==0:
        s.append(0)
    else: 
        s.append(max)
    a=[0]
    cnt=cnt+1

for i in range(cnt):
    if s[i]==0:
        print("none")
    else:
        print(s[i])
        
"""
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
40
10
99
none
20
"""

Submission status: Wrong Answer

Solution code:
n=5
m=5
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()]
    m1=m2=val[0]
    for i in range(1,n):
        if val[i]>=m1:
             m1=val[i]
        elif val[i]>m2:
             m2=val[i];
    sum=m1+m2
    if sum>m:
        sum=0
    A.append(sum)

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

Submission status: Wrong Answer

Solution code:
n=5
m=5
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()]
    m1=m2=val[0]
    for i in range(1,n):
        if val[i]>=m1:
             m1=val[i]
        elif val[i]>m2:
             m2=val[i];
    sum=m1+m2
    if sum>m:
        sum="NONE"
    A.append(sum)

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

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
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
if max==0:
    print("NONE")
else:
    print(max)

Submission status: Wrong Answer

Solution code:
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=[int(0) for i in range(n)]
    ans2=[int(0) for i in range(n)]
    mm=0
    for i in range(0,n):
        for j in range(i+1,n):
            if i==j:
                break
            ans1[i]=val[i]+val[j]
        if ans1[i]>mm and ans1[i]<m:
            mm=ans1[i]

    A.append(mm)
    z=z+1

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

Submission status: Wrong Answer

Solution code:
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=[int(0) for i in range(n)]
    ans2=[int(0) for i in range(n)]
    mm=0
    for i in range(0,n-1):
        for j in range(i+1,n):
            if i==j:
                break
            ans1[i]=val[i]+val[j]
        if ans1[i]>mm and ans1[i]<m:
            mm=ans1[i]

    A.append(mm)
    z=z+1

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

Submission status: Wrong Answer

Solution code:
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)

Submission status: Wrong Answer

Solution code:
while True:
    t = 0
    n,m = map(int,input().split())
    if n != 0:
        a = list(map(int,input().split()))
        a.sort()
        for i in range(n - 1):
            k = a[-i-1]
            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

Submission status: Wrong Answer

Solution code:
answer=[]
while True:
    t = 0
    n,m = map(int,input().split())
    if n != 0:
        a = list(map(int,input().split()))
        a.sort()
        for i in range(n - 1):
            k = a[-i-1]
            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:
            answer.append("NONE")
        else:
            answer.append(t)
    else:
        break
for i in range(len(answer)):
    print(answer[i])

Submission status: Wrong Answer

Solution code:
answer=[]
while True:
    t = 0
    n,m = map(int,input().split())
    if n != 0:
        a = list(map(int,input().split()))
        a.sort()
        for i in range(n - 1):
            k = a[-i-1]
            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:
            answer.append("NONE")
        else:
            answer.append(t)
    else:
        break
for i in range(len(answer)):
    print(answer[i])

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Accepted

Solution code:
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')

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

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')

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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())

Submission status: Accepted

Solution code:
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")

Submission status: Accepted

Solution code:
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")

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
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')

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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

Submission status: Accepted

Solution code:
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")

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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])

Submission status: Accepted

Solution code:
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")

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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])

Submission status: Accepted

Solution code:
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])

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:

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)