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 "bits/stdc++.h"
using namespace std;
using LL = long long;
using ULL = unsigned long long;
const double PI = acos(-1);
template<class T>constexpr T INF() { return ::std::numeric_limits<T>::max(); }
template<class T>constexpr T HINF() { return INF<T>() / 2; }
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { -1,0,1,0 }, dy[4] = { 0,-1,0,1 };
int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++)if ((n >> i) & 1)cnt++; return cnt; }
int d_sum(LL n) { int ret = 0; while (n > 0) { ret += n % 10; n /= 10; }return ret; }
int d_cnt(LL n) { int ret = 0; while (n > 0) { ret++; n /= 10; }return ret; }
LL gcd(LL a, LL b) { if (b == 0)return a; return gcd(b, a%b); };
LL lcm(LL a, LL b) { LL g = gcd(a, b); return a / g*b; };
# define ALL(qpqpq)           (qpqpq).begin(),(qpqpq).end()
# define UNIQUE(wpwpw)        (wpwpw).erase(unique(ALL((wpwpw))),(wpwpw).end())
# define LOWER(epepe)         transform(ALL((epepe)),(epepe).begin(),TL<char>)
# define UPPER(rprpr)         transform(ALL((rprpr)),(rprpr).begin(),TU<char>)
# define FOR(i,tptpt,ypypy)   for(LL i=(tptpt);i<(ypypy);i++)
# define REP(i,upupu)         FOR(i,0,upupu)
# define INIT                 std::ios::sync_with_stdio(false);std::cin.tie(0)
# pragma warning(disable:4996)

int n, m;
int a[1010];

int main() {
	while (cin >> n >> m&&n&&m) {
		REP(i, n)cin >> a[i];
		int ret = 0;
		REP(i, n)REP(j, n) {
			if (i == j)continue;
			if (a[i] + a[j] <= m)ret = max(a[i] + a[j], ret);
		}
		if (ret == 0) {
			cout << "NONE" << endl;
		}
		else {
			cout << ret << endl;
		}
	}
}

C++: #include <iostream>
#include <algorithm>
using namespace std;
int a[1000];
int main(){
	int n,m;
	while(scanf("%d%d",&n,&m)&&!(n==0&&m==0)){
		for(int i=0; i<n; i++){
			scanf("%d",&a[i]);
		}
		sort(a,a+n);
		bool ok = false;
		int goo = -1;
		for(int i=n-1; i>=1; i--){
			for(int j=i-1; j>=0; j--){
				int sum = a[i]+a[j];
				if(sum<=m){
					ok = true;
					goo = max(goo,sum);
				}
			}
		}
		if(ok==false){
			printf("NONE\n");

		}else printf("%d\n",goo);
	}
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}
typedef long long int ll;

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define endl "\n"
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//-------------------------------------

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    while(1) {
        int n, m;
        cin >> n >> m;
        if(n == 0 && m == 0) {
            break;
        }
        vector<int> a(n);
        for(int i = 0; i < n; i++) {
            cin >> a[i];
        }
        int ans = -INF;
        for(int i = 0; i < n; i++) {
            for(int j = i + 1; j < n; j++) {
                int tmp = a[i] + a[j];
                if(tmp <= m) {
                    chmax(ans, tmp);
                }
            }
        }
        if(ans == -INF) {
            cout << "NONE" << endl;
        } else {
            cout << ans << endl;
        }
    }
}

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

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

C++: #include<bits/stdc++.h>
using namespace std;
int main(){
  int n,m;
  while(1){
    cin>>n>>m;
    if(n==0 && m==0) break;
    int a[1001];
    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) continue;
        ans=max(ans,a[i]+a[j]);
      }
    }
    if(ans==0) cout<<"NONE"<<endl;
    else cout<<ans<<endl;
  }
  return 0;
}

C++: #include <iostream>

using namespace std;

int main() {
    int a[1001];
    int n, m;
    while (cin >> n >> m) {
        if (n == 0 && m == 0) { break; }
        for (int i = 0; i < n; i++) {
            cin >> a[i];
        }
        int ans = -1;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if (a[i] + a[j] <= m && a[i] + a[j] > ans) {
                    ans = a[i] + a[j]
                }
            }
        }
        cout << (ans == -1 ? "NONE" : string(ans)) << endl;
    }
    return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
using namespace std;

#define sum vec[i] + vec[j]

int main() {
	int n, m, near; vector<int> vec;
	while (1) {
		cin >> n >> m; if (n == 0 && m == 0) break;
		near = 0; vec.resize(n);
		for (int i = 0; i < n; i++) cin >> vec[i];
		sort(vec.begin(), vec.end(), greater<int>());
		for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) {
			if (i == j) continue;
			if (sum <= m && sum >= near) near = sum;
			if (near == m) break;
		}
		if (near == 0) cout << "NONE" << endl;
		else cout << near << endl;
		for (int i = 0; i < n; i++) vec.pop_back();
	}
	return 0;
}