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 <cstring>
#include <cstdlib>
#include <cassert>
#include <climits>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <fstream>

using namespace std;
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REPR(i,n) for(int i=(n)-1;i>=0;i--)
#define ALL(s) (s).begin(), (s).end()
#define so(V) sort(ALL(V))
#define rev(V) reverse(ALL(V))
#define uni(v) v.erase( unique(ALL(v)) , v.end());

typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<bool> vb;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;
const int INF = (1 << 29);
const ll LINF = 1e18;
const double PI = acos(-1);

template<typename T>vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...)); }
template<typename T, typename U, typename... V>
typename enable_if<is_same<T, U>::value != 0>::type
fill_v(U & u, const V... v) { u = U(v...); }
template<typename T, typename U, typename... V>
typename enable_if<is_same<T, U>::value == 0>::type
fill_v(U & u, const V... v) { for (auto& e : u) fill_v<T>(e, v...); }
template<class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T& a, const T& b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N, M;
	cin >> N >> M;
	while (N != 0) {
		vi A(N);
		REP(i, N) {
			cin >> A[i];
		}
		int ans = -1;
		REP(i, N) {
			REP(j, N) {
				if (i == j)continue;
				if (A[i] + A[j] > M)continue;
				chmax(ans, A[i] + A[j]);
			}
		}
		if (ans == -1) {
			cout << "NONE" << endl;
		}
		else {
			cout << ans << endl;
		}
		cin >> N >> M;
	}
	return 0;
}

C++: #include <iostream>

using namespace std;

int main(void){
  while(1){
    int n , m;
    cin >> n;
    cin >> m;
    if(n == 0 && m == 0){
      return 0;
    }

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

    int sum[n][n];

    for(int i = 0 ; i < n ; i ++){
      for(int j = 0 ; j < n ; j++){
        if(i != j){ sum[i][j] = a[i] + a[j]; }
        else{ sum[i][j] = -1000; }
      }
    }

    int max = -1000;

    for(int i = 0 ; i < n ; i++){
      for(int j = 0 ; j < n ; j++){
        if( sum[i][j] > max && sum[i][j] < m ){
          max = sum[i][j];
        }
      }
    }

    if(max == -1000){
      cout << "NONE" << endl;
    }else{
      cout << max << endl;
    }
  }

}

C++: #include <stdio.h>
#include <cmath>
#include <algorithm>
typedef long long int ll;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000001
using namespace std;


int main(){

	int N,M,maximum,table[1000];

	while(true){
		scanf("%d %d",&N,&M);
		if(N == 0 && M == 0)break;

		maximum = 0;

		for(int i = 0; i < N; i++)scanf("%d",&table[i]);

		for(int i = 0; i < N-1; i++){
			for(int k = i+1; k < N; k++){
				if(table[i]+table[k] <= M){
					maximum = max(maximum,table[i]+table[k]);
				}
			}
		}

		if(maximum == 0){
			printf("NONE\n");
		}else{
			printf("%d\n",maximum);
		}
	}

	return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(void){
    int n,m;
    while(cin>>n>>m){
        vector<int> a(n);
        for(int i=0;i<n;i++){
            cin>>a[i];
        }
        vector<int> b(n*(n-1)/2);
        int x=0;
        for(int i=0;i<n;i++){
            for(int j=i+1;j<n;j++){
                b[x]=a[i]+a[j];
                x++;
            }
        }
        sort(b.begin(),b.end());
        for(int i=0;i<x;i++){
            if(b[0]>m){
                cout<<"NONE"<<endl;
                break;
            }
            else if(b[i]>m){
                cout<<b[i-1]<<endl;
                break;
            }
        }
    }
    return 0;
}

C++: 
#include<iostream>
#include<vector>
using namespace std;
int main(){
  int n=1;
  int m=1;
  int count=0;
  vector<int> sum(50000, 0);
  vector<int> flg(50000, 0);

  while(n!=0&&m!=0)
    {
      cin >> n >> m;
      if(n==0&&m==0)
	{
	  break;
	}
      vector<int> a(n);
      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(a[i]+a[j]>sum[count] && a[i]+a[j]<=m && i!=j)
	    {
	      sum[count] = a[i]+a[j];
	      flg[count] = 0;
	    } 
	  else
	    {
	      if(sum[count]==0)
		{
		  flg[count]=1;
		}
	    }
	}
      }
      count++;
    }
  for(int i=0;i<count;i++)
    {
        if(flg[i]==0)
	{
	  cout << sum[i] << endl;
	}
      if(flg[i]==1)
	{
	  cout << "NONE" << endl;
	}
    }
  return 0;
}