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().split())
    if (n,m)==(0,0):
        break
    a=list(map(int,input().split()))
    b=0
    for i in range(n):
        for j in range(i+1,n):
            if a[i]+a[j]>m:
                continue
            else:
                b=max(b,a[i]+a[j])
    if b==0:
        print("NONE")
    else:
        print(b)

Solution (Python):
while True:
    ans=[]
    n,m = map(int,input().split())
    
    if n==0 and m==0:
        break
    
    a = list(map(int,input().split()))
    
    a = sorted(a)

    b = 0
    
    for i in range(n):
        for j in range(i+1,n):
            b = a[i]+a[j]
        
            if b <= m:
                ans.append(b)
            
            else:
                break
    if len(ans)==0:
        print("NONE")
    else:
        print(max(ans))

Solution (Python):
while True:
    n, m = [int(num) for num in input().split()]
    if n == m == 0:
        break
    items = sorted([int(num) for num in input().split()])
    answer = 0
    j = n - 1
    for i in range(n):
        while j > i and items[i] + items[j] > m:
            j -= 1
        if j <= i:
            break
        answer = max(answer, items[i] + items[j])
    print(answer if answer > 0 else "NONE")

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

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

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
    po = n - 1
    for i in range(n):
        while po > i and a[i] + a[po] > m:
            po -= 1
        if po <= i:
            break
        ans = max(ans, a[i] + a[po])
    print(ans if ans > 0 else 'NONE')

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

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

Solution (Python):
from copy import copy

def get_input():
    data_list = input().split()
    for i, v in enumerate(data_list):
        data_list[i] = int(v)
    return data_list


def remove_over_budeget(value_list, budget):
    tmp_list = copy(value_list)
    for i, v in enumerate(tmp_list):
        if v >= budget:
            del value_list[i:]
            return value_list
    return value_list

def get_max_value_list(value_list,budget):
    if value_list == []: 
        return "NONE"
    max_value = 0
    for i in range(0, len(value_list)-1):
        for j in range(i+1,len(value_list)):
            
            
            combination_plan = value_list[i] + value_list[j]
            if combination_plan <= budget and combination_plan > max_value:
                max_value = combination_plan
    if max_value == 0:
        return "NONE"
    return max_value





if __name__ == "__main__":
    while True:
        item_num, budget = get_input()
        if item_num == 0:
            break
        value_list = get_input()
        value_list.sort()
        value_list = remove_over_budeget(value_list, budget)
        max_value = get_max_value_list(value_list,budget)
        
        print(max_value)

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 1:
    n,m = map(int,input().split())
    if n==0:break
    a = list(map(int,input().split()))
    c = []
    for i in range(n-1):
        for j in range(i+1, n):
            if a[i]+a[j] <= m:
                c.append(a[i]+a[j])
    if len(c) == 0:
        print('NONE')
    else:
        print(max(c))

Solution (Python):
from itertools import combinations
while True:
    n, p = [int(x) for x in input().split()]
    if n == 0 and p == 0:
        break
    L = [int(x) for x in input().split()]
    m = -1
    for i, j in combinations(L,2):
        if i+j <=p:
            m = max(m,i+j)
    if m > 0:
        print(m)
    else:
        print("NONE")

Solution (Python):
import os,re,sys,operator,math
from collections import Counter,deque
from operator import itemgetter
from itertools import accumulate,combinations,groupby
from sys import stdin,setrecursionlimit
from copy import deepcopy
import heapq

setrecursionlimit(10**6)
while 1:
    n,m=map(int,stdin.readline().rstrip().split())
    if (n,m)==(0,0):
        break
    a=[int(i) for i in stdin.readline().rstrip().split()]
    ans=0
    for i in range(n-1):
        for j in range(i+1,n):
            t=a[i]+a[j]
            if t<=m:
                ans=max(ans,t)
    print(ans if ans!=0 else "NONE")

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

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

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

            ans = max(ans, a[i] + a[j])

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

Solution (Python):
ans_list = []

while True:
    n,m = map(int,input().split())
    if (n,m) == (0,0):
        break
    A = list(map(int,input().split()))
    N = len(A)
    ans = 0
    for i in range(N):
        for j in range(i+1,N):
            res = A[i] + A[j]
            if res <= m:
                ans = max(ans, res) 
    if ans == 0:
        ans = "NONE"
    ans_list.append(ans)

for ans in ans_list:
    print(ans)

Solution (Python):
import sys
input = sys.stdin.readline

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

Solution (Python):
import sys
import re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, log2,gcd
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()


def INT(): return int(input())


def MAP(): return map(int, input().split())


def LIST(): return list(map(int, input().split()))


sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

ans=[]

while 1:
    n,m=MAP()
    if n==0 and m==0:
        break
    else:
        a=LIST()
        
        lis=[sum(x) for x in list(combinations(a,2)) if sum(x)<=m]
        if not lis:
            ans.append('NONE')
        else:
            ans.append(max(lis))

for x in ans:
    print(x)

Solution (Python):
import itertools
def main(n,m):
    a = list(map(int, input().split()))
    select = list(itertools.combinations(range(n), 2))
    ans = 0
    for x,y in select:
        if ans < a[x] + a[y] <= m:
            ans = a[x] + a[y]
    if ans == 0:
        print("NONE")
    else:
        print(ans)
    return 1
while 1:
    n, m = map(int, input().split())
    if n == m == 0:
        break
    main(n,m)

Solution (Python):


import itertools

def main():
    while True:
        n, m = map(int, input().split())
        if n == 0 : break
        ns = list(map(int, input().split()))
        ans = -1
        for p in itertools.permutations(ns, 2):
            if sum(p) <= m:
                ans = max(ans, sum(p))
        if ans == -1:
            print('NONE')
        else:
            print(ans)
main()

Solution (Python):
for v in range(1000):
  s,t = input().split()
  s = int(s)
  t = int(t)
  if s == 0:
    break
  else:
    x=[]
    A = input().split()
    B = [int(l) for l in A]
    for i in range(s):
      for j in range(s):
        if i==j:
          pass
        else:
          w=B[i]+B[j]
          if w <= t:
             x.append(w)
          else:
            pass 
    lll=len(x)
    if lll == 0:
      print("NONE")
      continue
    else:  
      mx = max(x)
      print(mx)
      continue

Solution (Python):
def solve(n, m, a):
    ans = 0
    r = n - 1
    for l in range(n):
        while r > l and a[l] + a[r] > m:
            r -= 1
        if r <= l:
            break
        ans = max(ans, a[l] + a[r])
    print(ans if ans > 0 else 'NONE')


if __name__ == '__main__':
    while True:
        n_imput, m_imput = map(int, input().split())
        if n_imput == 0:
            break
        a_imput = sorted(list(map(int, input().strip().split())))
        solve(n_imput, m_imput, a_imput)

Solution (Python):

while True:
    n, m = map(int, input().split())
    if n == 0:
        exit()
    a = list(map(int, input().split()))
    ans = -1
    for i in range(n):
        for j in range(n):
            if i == j: continue
            s = a[i] + a[j]
            if s <= m:
                ans = max(ans, s)
    print([ans, 'NONE'][ans == -1])

Solution (Python):
while True:

    n,m = [int(x) for x in input().split()]
    if n == m == 0:
        break
    a = [int(x) for x in input().split()]

    ans = -1

    for i in range(n):
        for j in range(n):
            if i == j:
                continue
            if ans < a[i]+a[j] and a[i]+a[j] <= m:
                ans = a[i]+a[j]

    if ans == -1:
        print("NONE")
    else:
        print(ans)

Solution (Python):
import itertools

while True:
    item_n, money = [int(i) for i in input().split()]
    if item_n == money == 0:
        break
 		
    value_lst = [int(i) for i in input().split()]
 	
    max_value = -1
    can_buy = False
 	
    for i1, i2 in itertools.combinations(value_lst, 2):
        if i1 + i2 > max_value and i1 + i2 <= money:
        	max_value = i1 + i2
        	can_buy = True
        	
    if(can_buy):	
        print(max_value)
    else:
    	print('NONE')

Solution (Python):
def main():
    while True:
        n,m = map(int,input().split())
        if not n and not m:
            return
        aa = list(map(int,input().split()))
        ans = 0
        for i in range(n):
            for j in range(n):
                if i == j:
                    continue
                tmp = aa[i] + aa[j]
                if tmp <= m:
                    ans = max(ans, tmp)
        if ans == 0:
            print("NONE")
        else:
            print(ans)

if __name__ == '__main__':
    main()

Solution (Python):
import bisect

while True:
    n,m = map(int,input().split())
    if [n,m] == [0,0]:
        break
    
    a = list(map(int,input().split()))
    a.sort()
    res = -1
    
    for i in range(n):
        k = bisect.bisect_right(a,m-a[i])
        if k == i+1:
            k -= 1
        if k != 0:
            res = max(res,a[i]+a[k-1])
    if res == -1:
        print('NONE')
    else:
        print(res)

Solution (Python):
ans_list = []

def solve():
    n,m = map(int,input().split())
    if (n,m) == (0,0):
        return "end"
    a = list(map(int,input().split()))
    res = -float("inf")
    n = len(a)
    for i in range(n):
        for j in range(i+1,n):
            cand = a[i] + a[j]
            if res < cand <= m:
                res = cand
    if res == -float("inf"):
        res = "NONE"
    return res

while True:
    ans = solve()
    if ans == "end":
        break
    ans_list.append(ans)

for ans in ans_list:
    print(ans)

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

    if len(total) > 0:
        print(max(total))
    else:
        print("NONE")

Solution (Python):
while True:

    items,money=list(map(int,input().split()))

    if money==0 and items==0:
        break

    prices=list(map(int,input().split()))

    times=int(items*(items-1)/2)

    sum_list=[]

    low=0
    high=1
    sum=0
    i = 0

    while True:
        

        if high>items-1:
            low+=1
            high=low+1
        if low==items-1:
            break
        
        sum = prices[low] + prices[high]
        
        if sum<=money:
            sum_list.append(sum)
            high+=1
            i+=1
        else:
            high+=1

    if i==0:
        print("NONE")
    else:
        print(max(sum_list))

Solution (Python):
while True:
    n, m = map(int,input().split())
    if (n,m) == (0,0):break
    price = list(map(int, input().split()))
    price.sort()
    summ = []
    k = -1
    j = 0
    if price[0]+price[1] > m:
            print('NONE')
            continue
    while True:
        if j == n + k:break
        elif price[j] +  price[k] <= m:
            summ.append(price[j] +  price[k])
            j += 1
        else:
            k -= 1
    summ.sort()
    print(summ[-1])

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

Solution (Python):
while 1:
  n,m= map(int, input().split())
  if n==0 and m==0:
    break
  A = list(map(int, input().split()))
  B = []
  for i in range(n):
    for j in range(1+i,n):
      b = A[i]+A[j]
      B.append(b)
  

  B = sorted(B, reverse=1)
  
  B = [x for x in B if x <= m]
  print(B[0] if len(B) > 0 else "NONE")

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

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

    A = list(map(int, input().split()))
    
    ans = 0
    for i in range(len(A)):
        for j in range(i+1, len(A)):
            if A[i] + A[j] > m:
                continue
            else:
                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:
    break
  else:
    
    a = sorted(list(map(int, input().strip().split())))
    
    a_sum = 0
    
    for i in range(0,n-1):
      for j in range(i+1,n):
        if max(a_sum, a[i] + a[j]) <= m :
          a_sum = max(a_sum, a[i] + a[j])
    
    if a_sum ==0 :
      print("NONE")
    else :
      print(a_sum)

Solution (Python):

while True:
  n, m = map(int, input().split())
  if n+m == 0:
    break
  a = sorted(list(map(int, input().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):
"""
a = int(input())

b, c = map(int, input().split())

s = input()

print(str(a+b+c) + " " + s)
"""


def main():
	while(1):

		N,n = map(int, input().split())
		
		if N == 0 and n == 0:
			break

		a = list(map(int, input().split()))
		ans = 0
		for i in range(N):
			for j in range(i+1,N):
				if a[i]+a[j] <= n and a[i]+a[j] > ans:
					ans = a[i]+a[j]

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


if __name__ == '__main__':
    main()

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

    items = []
    for i in input().split(" "):
        items.append(int(i))


    
    items2 = items
    sums = []
    for i in range(len(items)):
        for j in range(len(items)):
            if i == j:
                continue
            sums.append(items[i] + items2[j])

    sums.sort(reverse=True)
    for i in range(len(sums)):
        if sums[i] <= m:
            print(sums[i])
            break
        if i == len(sums) - 1:
            print("NONE")

Solution (Python):
import itertools

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

    data = list(map(int, input().split()))

    ans = 0
    for v in itertools.combinations(data, 2):
        if sum(v) <= m and sum(v) > ans:
            ans = sum(v)

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

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**13
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    rr = []

    def f(n,m):
        a = LI()
        r = None
        for i in range(n):
            for j in range(i+1,n):
                t = a[i] + a[j]
                if m >= t and (r is None or r < t):
                    r = t

        if r is None:
            return 'NONE'
        return r

    while 1:
        n,m = LI()
        if n == 0:
            break
        rr.append(f(n,m))

    return '\n'.join(map(str,rr))


print(main())

Solution (Python):
def main():
  while True:
    n, m = map(int, input().split())
    if n == 0:
      break
  
    items = sorted(list(map(int, input().split())))
    ans = 0
    for i in range(n - 1):
      p1 = items[i]
      for j in range(i + 1, n):
        p2 = p1 + items[j]
        if p2 > m:
          break
        if ans < p2:
          ans = p2
    if ans != 0:
      print(ans)
    else:
      print("NONE")
  
main()

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

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 1:
    n,m=map(int,input().split())
    if n==0:
        break
    d=list(map(int,input().split()))
    mx=-1
    for i in range(n):
        for j in range(i+1,n):
            if d[i]+d[j]<=m:
                mx=max(d[i]+d[j],mx)
    print(mx if mx!=-1 else 'NONE')