Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func main() {
	io := NewIo()
	defer io.Flush()
	for {
		n, m := io.NextInt(), io.NextInt()
		if n == 0 {
			break
		}
		a := make([]int, n)
		for i := 0; i < n; i++ {
			a[i] = io.NextInt()
		}
		ans := 0
		for i := 0; i < n; i++ {
			for j := i + 1; j < n; j++ {
				if a[i]+a[j] <= m {
					ans = intMax(a[i]+a[j], ans)
				}
			}
		}
		if ans == 0 {
			io.Println("NONE")
		} else {
			io.Println(ans)
		}
	}
}

func intMax(a, b int) int {
	if a < b {
		return b
	}
	return a
}

// I/O template
type Io struct {
	reader    *bufio.Reader
	writer    *bufio.Writer
	tokens    []string
	nextToken int
}

func NewIo() *Io {
	return &Io{
		reader: bufio.NewReader(os.Stdin),
		writer: bufio.NewWriter(os.Stdout),
	}
}

func (io *Io) Flush() {
	err := io.writer.Flush()
	if err != nil {
		panic(err)
	}
}

func (io *Io) NextLine() string {
	var buff []byte
	for {
		line, isPrefix, err := io.reader.ReadLine()
		if err != nil {
			panic(err)
		}
		buff = append(buff, line...)
		if !isPrefix {
			break
		}
	}
	return string(buff)
}

func (io *Io) Next() string {
	for io.nextToken >= len(io.tokens) {
		line := io.NextLine()
		io.tokens = strings.Fields(line)
		io.nextToken = 0
	}
	s := io.tokens[io.nextToken]
	io.nextToken++
	return s
}

func (io *Io) NextInt() int {
	i, err := strconv.Atoi(io.Next())
	if err != nil {
		panic(err)
	}
	return i
}

func (io *Io) NextFloat() float64 {
	i, err := strconv.ParseFloat(io.Next(), 64)
	if err != nil {
		panic(err)
	}
	return i
}

func (io *Io) Println(a ...interface{}) {
	fmt.Fprintln(io.writer, a...)
}

func (io *Io) Printf(format string, a ...interface{}) {
	fmt.Fprintf(io.writer, format, a...)
}

func (io *Io) PrintIntSlice(a []int) {
	b := []interface{}{}
	for _, x := range a {
		b = append(b, x)
	}
	io.Println(b...)
}

func (io *Io) PrintStringSlice(a []string) {
	b := []interface{}{}
	for _, x := range a {
		b = append(b, x)
	}
	io.Println(b...)
}

func Log(name string, value interface{}) {
	fmt.Fprintf(os.Stderr, "%s=%+v\n", name, value)
}

func ExampleIo() {
	io := NewIo()
	defer io.Flush()
	a := make([]int, 0, 3)
	a[0], a[1], a[2] = io.NextInt(), io.NextInt(), io.NextInt()
	io.Println(a)
	io.PrintIntSlice(a)
	Log("io", a)
}

C++: #include<iostream>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int n,m,a[1005];
int main(){
	while(1){
		cin>>n>>m; if(n==0) return 0;
		rep(i,n) cin>>a[i];
		int ans = 0;
		rep(i,n) rep(j,n){
			if(i == j) continue;
			if(a[i]+a[j] <= m) ans = max(ans,a[i]+a[j]);
		}
		if(ans == 0) cout << "NONE" << endl;
		else cout << ans << endl;
	}
}

C++: #include "bits/stdc++.h"
using namespace std;
#define int long long
#define endl '\n'
int mod=1e9+7;
int mod2=998244353;

signed main(){
  while(true){
    int n,m;
    cin>>n>>m;
    if(!n&&!m)break;
    vector<int> a(n);
    for(int i=0;i<n;i++)cin>>a[i];
    int ans=0;
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
        if(i!=j&&a[i]+a[j]<=m)ans=max(ans,a[i]+a[j]);
      }
    }
    if(ans)cout<<ans<<endl;
    else cout<<"NONE"<<endl;
  }
}

C++: using namespace std;
#include <iostream>
#include <string.h>
#include <algorithm>

int main()
{

    int n,m,i,x, v[1010],ok,smax=-1,s,j,st,dr,mij;

    cin>>n>>m;

    while(n!=0 && m!=0)
    {
        smax=-1;
        for(i=1; i<=n; i++)
        cin>>v[i];

        sort(v+1, v+1+n);

        ok=1;
        for(i=1; i<=n && ok; i++)
        {
            x=m-v[i];
            if(x<=0) ok=0;
            st=i+1;
            dr=n;

            while(st<=dr && ok)
            {
                mij=(st+dr)/2;

                if(v[mij]==x && i!=mij)
                {
                    smax=m;
                    ok=0;
                }
                else if(v[mij]>x) dr=mij-1;
                else
                {
                    if(v[mij]+v[i]>smax && i!=mij) smax=v[mij]+v[i];
                    st=mij+1;
                }

            }


        }

        if(smax!=-1) cout<<smax<<'\n';
        else cout<<"NONE\n";

        cin>>n>>m;

    }





    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;

int main(){
        int n, m;
        while (cin >> n >> m && n != 0 || m != 0){
                int money = 0;
                vector<int> a(n);
                for (int i = 0; i < n; i++) cin >> a[i];
                for (int i = 0; i < n - 1; i++){
                        for (int j = i + 1; j < n; j++){
                                if (a[i] + a[j] <= m) money = max(money, a[i] + a[j]);
                        }
                }
                if (money == 0) cout << "NONE" << endl;
                else cout << money << endl;
        }
        return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;

void solve(int n, int m) {
    int a[n];
    for (auto &x : a) cin >> x;
    int ans = -1;
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            if (a[i] + a[j] <= m) {
                ans = max(ans, a[i] + a[j]);
            }
        }
    }
    cout << (ans == -1 ? "NONE" : to_string(ans)) << endl;
}

int main() {
    int n, m;
    while (true) {
        cin >> n >> m;
        if (!n && !m) return 0;
        solve(n, m);
    }
}

C++: #include <bits/stdc++.h>

#define REP(i,n) for (int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()

using namespace std;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    while (true) {
        int n, m;
        cin >> n >> m;
        if (n == 0) break;
        vector<int> a(n);
        REP(i, n) cin >> a[i];

        sort(all(a));

        int result = 0;

        REP(i, n) {
            auto ub = upper_bound(a.begin(), a.begin() + i, m - a[i]);
            if (ub != a.begin()) {
                result = max(result, a[i] + *(ub - 1));
            }
        }

        if (result) {
            cout << result << '\n';
        } else {
            cout << "NONE\n";
        }
    }
    cout << flush;

    return 0;
}

C++: #include <iostream>
#define MAX 1000
using namespace std;
int a[MAX];

int main(){
    while(true){
        int n,m,maxsum = 0;
        cin >> n >> m;
        if(n == 0 && m == 0)break;

        for(int i = 0;i < n;i++)
            cin >> a[i];
        
        for(int i = 1;i < n -1;i++){
            for(int j = i + 1;j < n;j++){
                if((a[i] + a[j] <= m))
                    maxsum = max(maxsum,a[i] + a[j]);
            }
        }

        if(maxsum > m || maxsum == 0)
            cout << "NONE" << endl;
        else
            cout << maxsum << endl;
    }

    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n,m;
int a[2001];

int main(void){
	while(1){
		scanf("%d%d",&n,&m);
		if(n==0 && m==0)break;
		int res=0;
		for(int i=0;i<n;i++){
			scanf("%d",&a[i]);
		}
		for(int i=0;i<n;i++){
			for(int j=i+1;j<n;j++){
				if(a[i]+a[j]<=m){
					res=max(res,a[i]+a[j]);
				}
			}
		}
		if(res==0)printf("NONE\n");
		else printf("%d\n",res);
	}
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Vec = vector<ll>;
#define REP(i, m, n) for(ll i = (m); i < (n); ++i)
#define rep(i, n) REP(i, 0, n)
template <typename T>
bool chmax(T &a, const T b){if(a < b){a = b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T b){if(a > b){a = b; return true;} return false;}
constexpr ll LINF = 1e18+1;
constexpr ll MOD = 1e9+7;

int main(void) {
	ll n, m;
	while(true){
	cin >> n >> m;
	if(n == 0 && m == 0) break;
	Vec a(n);
	rep(i, n) cin >> a[i];
	sort(a.begin(), a.end());

	ll ans = 0;
	rep(i, n){
		if(a[i] > m) break;
		auto p = upper_bound(a.begin(), a.end(), m - a[i]) - a.begin();
		if(p == 0) continue;
		--p;
		if(i == p) continue;
		chmax(ans, a[i] + a[p]);
	}
	if(ans != 0) cout << ans << endl;
	else cout << "NONE" << endl;
	}

	return 0;
}