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>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <climits>
#include <string>
#include <vector>
#include <utility>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cassert>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

const ll MOD = ll(1e9) + 7;
const ll INF = LLONG_MAX;
const ll MAX_N = 1 << 12;
const double EPS = 10e-8;
const double PI = 3.14159265359;
int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};

#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (ll i = n; i >= 0; i--)
#define FOR(i, m, n) for (ll i = m; i < n; i++)

int main() {
    while (1) {
        int n, m, a[1001], ans = -1;
        cin >> n >> m;
        if (n == 0) break;
        REP(i, n) cin >> a[i];
        REP(i, n) {
            FOR(j, i + 1, n) {
                if (a[i] + a[j] <= m) ans = max(ans, a[i] + a[j]);
            }
        }
        if (ans > 0)
            cout << ans << endl;
        else
            cout << "NONE" << endl;
    }
    return 0;
}

C++: #include<iostream>

using namespace std;

int main(){
  int n,m,a[1001];
  cin>>n>>m;
  int ans=0;

    for(int i=0;i<n;i++) cin>>a[i];

    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
        if(i!=j){
      if(a[i]+a[j]<=m) ans=max(ans,a[i]+a[j]);
}
}
}
    if(ans) cout<<ans<<endl;
    else cout<<"NONE"<<endl;

return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <algorithm>

using namespace std;

int N, V[1005];
int SMAX;

int bin_search2(int x) {
    int pw = 1;

    while(pw <= N) {
        pw <<= 1;
    }

    pw >>= 1;

    int pos = 0;

    while(pw) {
        if(pos + pw <= N) {
            if(V[pos + pw] <= x) {
                pos += pw;
            }
        }

        pw >>= 1;
    }

    return pos;
}

int main() {
//    #ifndef ONLINE_JUDGE
//    freopen("input.txt","r",stdin);
//    #endif // ONLINE_JUDGE

    scanf("%d %d\n", &N, &SMAX);

    while(N + SMAX > 0) {
        for(int i = 1; i <= N; ++i) {
            scanf("%d", &V[i]);
        }

        sort(V + 1, V + 1 + N);

        int mx = 0;
        for(int i = 1; i <= N && V[i] < SMAX; ++i) {
            int dif = SMAX - V[i];
            int pos = bin_search2(dif);
            if(pos != i) {
                if(V[i] + V[pos] <= SMAX && pos > 0) {
                    if(V[i] + V[pos] > mx) {
                        mx = V[i] + V[pos];
                    }
                }
            }
        }

        if(mx == 0) {
            cout << "NONE\n";
        }
        else {
            cout << mx << '\n';
        }

        cin >> N >> SMAX;
    }

    return 0;
}

C++: #include<iostream>
#include<vector>
using namespace std;
int main(){
  vector<int> a;
  int n,m,b,max=0;
  while(n!=0 && m!=0){
    max=0;
    cin>>n>>m;
    for(int i=0;i<n;i++){
      cin>>b;
      a.push_back(b);
    }
  
    for(int j=0;j<n;j++){
      for(int k=0;k<n;k++){
	if(j!=k){
	  if(max<a[j]+a[k] && a[j]+a[k]<=m){
	    max=a[j]+a[k];
	    //cout<<max;
	  }
	}
      }
    }
    if(max==0 && n!=0&&m!=0){
      cout<<"NONE"<<endl;
    }else if(n!=0&&m!=0){
      cout<<max<<endl;
    }
  }
}

C++: #include <iostream>
#define N 100000

int main(){
  int n,max;
  int A[N]={0},k=0;
  while(1){
    int p=0,tmp;
    std::cin>>n;
    int a[n]={0};
    std::cin>>max;
    if(n==0)break;
    for(int i=0;i<n;i++){
      std::cin>>a[i];
    }
    for(int i=0;i<n;i++){
      for(int j=i+1;j<n;j++){
	tmp=a[i]+a[j];
	if(tmp>=A[k]&&tmp<=max){
	  A[k]=tmp;
	  p++; 
	}
      }
    }
    if(p==0) A[k]=0;
    k++;
  }
  for(int i=0;i<k;i++){
    if(A[i]!=0){
      std::cout<<A[i]<<"\n";
    }else{
      std::cout<<"NONE\n";
    }
  }
}

C++: #include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;
#define ll long long
#define pb push_back

int main()
{
    int n,m,tmp;
    vector<string> x;
    while (1)
    {
        cin >> n >> m;
        if (n == 0)
        {
            break;
        }
        vector<int> a;
        for(int i=0; i<n; i++){
            cin >> tmp;
            a.push_back(tmp);
        }
        sort(a.begin(),a.end());
        int value = 0;
        int nearest = 0;
        for(int i=0; i<n; i++){ // O(n^2)かかるが少し早くなるようにしている
            for(int j=i+1; j<n; j++){
                value = a[i] + a[j];
                if(value == m){
                    nearest = value;
                    break;
                }
                if(value > nearest && value < m ){
                    nearest = value;
                }
                if(value > m){ // mを超えたら次の値を見る
                    j = n-1;
                }
                // cout << i << " " << j << endl;
            }
        }
        if(nearest!=0){
            char str[30];
            sprintf(str, "%d", nearest);
            x.push_back(str);
        } else {
            x.push_back("NONE");
        }

    }
    for (int i = 0; i < x.size(); i++)
    {
        cout << x[i] << endl;
    }
}

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

	static int n, m, ans;
	static int a[100000];
void input() {
	cin >> n;
	cin >> m;
	for (int i = 1; i < n + 1; i++) {
		cin >> a[i];
	}
}
void pre() {
	ans = 0;
}
void operate() {
	for (int i=1;i<n+1;i++) 
		for (int j = i + 1; j < n + 1; j++) {
			if ((a[i] + a[j] <= m)&(a[i] + a[j] > ans)) ans = a[i] + a[j];
		}
}
void output() {
	if (ans == 0) cout << "NONE";
	else cout << ans;
	cout << endl;
}
int main() {
	while (true) {
		input();
		if (n == 0)return 0;
		pre();
		operate();
		output();
	}
	return(0);
}