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++: /*Problem sennobushige 16D8104015E 18.5.16*/
#include <iostream>
#define N 1000000

int main(){
  int n=1,max;
  int A[50000]={0},k=0;


  while(n!=0){
    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-1;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++;
    //if(p!=0) std::cout<<sum<<"\n";
    //else std::cout<<"NONE\n";
  }
  for(int i=0;i<k;i++){
    if(A[i]!=0){
      std::cout<<A[i]<<"\n";
    }else{
      std::cout<<"NONE\n";
    }
   
  }



}

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

#define int long long

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int N, M;
  while ( cin >> N >> M, N ) {

    vector<int> a(N);
    for ( int i = 0; i < N; i++ ) {
      cin >> a[i];    
    }

    int ans = -1;
    for ( int i = 0; i < N; i++ ) {
      for ( int j = i+1; j < N; j++ ) {
	if ( i == j ) continue;	
	if ( a[i]+a[j] <= M ) ans = max(ans, a[i]+a[j]);
      }
    }

    if ( ans == -1 ) puts("NONE");
    else cout << ans << endl;
  }
  
  return 0;
}

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

using namespace std;

inline int ctoi(char c) { if(c < '0' || '9' < c) throw invalid_argument("ctoi error"); return c - '0'; }
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, k, n) for(int i = (int)(k); i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()

template <typename T>
inline T gcd(T x, T y){
	if (x <= 0 || y <= 0) throw invalid_argument("gcd error: x <= 0 or y <= 0");
	
	if(x < y) swap(x, y);
	T r = x % y;

	while(r != 0){
		x = y;
		y = r;
		r = x % y;
	}

	return y;
}
template <typename T>
inline T lcm(T x, T y){
	if (x <= 0 || y <= 0) throw invalid_argument("lcm error: x <= 0 or y <= 0");

	return x * y / gcd(x, y);
}

int main(){
	vector<vector<int>> vec_n;
	vector<vector<int>> vec;

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

		vector<int> v_n;
		v_n.push_back(n);
		v_n.push_back(m);
		vec_n.push_back(v_n);

		vector<int> v;
		rep(i, n)
		{
			int a;
			cin >> a;
			v.push_back(a);
		}

		vec.push_back(v);
	}

	rep(k, vec.size()){
		int ans = -1;

		int n = vec_n[k][0];
		int m = vec_n[k][1];

		rep(i, n - 1){
			REP(j, i + 1, n){
				int x = vec[k][i] + vec[k][j];
				if(x <= m && ans <= x) ans = x;
			}
		}

		if(ans == -1) cout << "NONE";
		else cout << ans;

		if(k != vec.size()) cout << endl;
	}

	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main(){
    int n, m, count = 0;
    while(1){
        cin >> n >> m;
        if(n == 0 && m == 0) break;
        vector< vector<int> > a(50000, vector<int>(n));
        rep(i, n){
            cin >> a.at(count).at(i);
        }
        int max_ = 0;
        for(int i = 0; i < n-1; i++){
            for(int j = i+1; j < n; j++){
                if(a.at(count).at(i)+a.at(count).at(j) <= m){
                    max_ = max(a.at(count).at(i)+a.at(count).at(j), max_);
                }
            }
        }
        if(max_ == 0){
            cout << "NONE" << endl;
        }
        else {
        cout << max_ << endl;
        }
        count++;
    }
    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
int main() {
    int N,Lim,l;
    while(1){
        scanf("%d %d",&N,&Lim);
        if(N==0){
            break;
        }
        int a[N];
        for(int i=0;i<N;i++){
            cin>>l;
            a[i]=l;
        }
        sort(a,a+N);
        int ans=0;

        int low,high,mid;
        int tmp,a_i;
        for(int i=0;i<N;i++){
            a_i = a[i];
            for(int j=i+1;j<N;j++){
                if (a_i+a[j]<=Lim){
                    ans = max(ans,a_i+a[j]);
                }
            }
        }
        if(ans==0){
            cout<<"NONE"<<endl;
        }
        else{
            cout << ans << endl;
        }
    }
	return 0;
}