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++: //author Eterna
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string>
#include<cstring>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<utility>
#include<cmath>
#include<climits>
#include<deque>
#include<functional>
#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
#define INF 0x7fffffff
#define maxn 1000
#define eps 1e-15
#define MOD ((int)(1e9+7))
#define ABS(x) ((x)>=0?(x):(-(x)))
#define pb(x) push_back(x)
#define lowbit(x) (x&-x)
#define mid (L+R)/2
#define Lson (index*2)
#define Rson (index*2+1)
using namespace std;
typedef long long ll;
inline int read() {
	char c;
	int ret = 0, sgn = 1;
	do { c = getchar(); } while ((c < '0' || c > '9') && c != '-');
	if (c == '-') sgn = -1; else ret = c - '0';
	while ((c = getchar()) >= '0' && c <= '9') ret = ret * 10 + (c - '0');
	return sgn * ret;
}
int n, m, arr[maxn + 5];
int main(void) 
{
	while (cin >> n >> m && (m&&n)) {
		bool flag = false;
		int ans = 0;
		for (int i = 1; i <= n; i++)arr[i] = read();
		for (int i = 1; i <= n; i++)
			for (int j = i + 1; j <= n; j++) {
				int sum = arr[i] + arr[j];
				if (sum > ans&&sum <= m) {
					flag = true;
					ans = sum;
				}
			}
		if (flag)cout << ans << endl;
		else cout << "NONE" << endl;
	}
	//system("pause");
	return 0;
}

C++: #include <iostream>
#include <vector> 
#include <cmath>
#include <algorithm>
#include <set>
#include <map>
#include <cerrno>
#include <cfenv>
#include <math.h>
#include <iomanip>
#include <limits>
#define ll long long int

using namespace std;

int main(){

    int n,m;

    vector<int> a(1000);

    while(true){

        cin >> n >> m;

        if(n==0&&m==0){
            break;
        }

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

        int max = -1;

        for(int i=0;i<n;i++){
            for(int j=i+1;j<n;j++){
                if(max < a[i]+a[j] && a[i]+a[j] <= m){
                    //cout << i << " " << j << endl;
                    max = a[i]+a[j];
                }
            }
        }

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

    return 0;
}

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

int main() {
  int n, m;
  vector<int> a;
  int flag = 0;

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

    for (int i = 0; i < n; i++) {
      int A;
      cin >> A;
      a.push_back(A);
    }

    vector<int> sum;

    for(int i = 0; i < n; i++) {
      for(int j = 0; j < n; j++) {
        if(i != j) {
          int Sum = a[i] + a[j];
          sum.push_back(Sum);
        }
      }
    }

    sort(sum.begin(), sum.end(), greater<int>());

    for(int i = 0; i < sum.size(); i++){
      if(sum[i] <= m) {
          cout << sum[i] << endl;
          flag = 1;
          break;
      }
    }

    if(flag == 0) {
      cout << "NONE" << endl;
    }

    sum.clear();
    a.clear();
  }
  return 0;
}

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

using namespace std;

int main(){

  int n,m;
  vector<int> a(1000);
  int sum=0;
  int max=0;
  
  while(1){
	cin>>n>>m;
	  
	  if(n == 0 && m  == 0)
		break;
	
	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){
		sum=0;
		sum=a[i]+a[j];
		
		if(sum>max && sum<=m)
		  max=sum;
			
	  }
	}

	cout<<max<<endl;
	
  }

  return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <bitset>
#include <cmath>
#include <string>
#define FI first
#define SE second
#define VE vector<int>
#define PB push_back
#define PA pair<int,int>
#define MA make_pair
#define LL long long
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,a,b) for(int i=b-1;i>=a;i--)
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
using namespace std;
//
const int INF=1e9+7;
const int MOD=1e9+7;
//
int main(){
  int N,M;
  int A[1000];
  while(1){
    int N,M;
    cin>>N>>M;
    if(N==0&&M==0){
      break;
    }
    FOR(i,0,N){
      cin>>A[i];
    }
    VE S;
    FOR(i,0,N){
      FOR(j,i+1,N){
        S.PB(A[i]+A[j]);
      }
    }
    sort(S.begin(),S.end());
    int ans=0,now=0;
    while(now<N*(N-1)/2){
      if(S[now]<=M){
        ans=S[now];
        now++;
      }else{
        break;
      }
    }
    if(now==0){
      cout<<"NONE"<<endl;
    }else{
      cout<<ans<<endl;
    }
  }
  return 0;
}

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

int main() {
    int n,m;
    while (cin >> n >> m)
    {
        if(n==0) break;
        vector<int> a(n);
        int ans=0;
        for (int i = 0; i < n; i++)
        {
            cin >> a[i];
        }
        sort(a.begin(), a.end());

        for (int i = 0; i < n-1; i++)
        {
            for (int j = i+1; j < n; j++)
            {
                if (a[i]+a[j]>m) break;
                ans=max(ans,a[i]+a[j]);
            }
        }
        if(ans==0){
            cout << "NONE" << endl;
        }else{
            cout << ans << endl;
        }
    }
}
//g++ -o a.exe a.cpp