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<iomanip>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<numeric>
using namespace std;

#define R(i,s,n) for(int i=s;i<n;i++)
#define D(i,n,s) for(int i=n-1;i>=s;i--)
typedef pair<int,int> P;


int main() {
  int n, m;

  while (cin >> n >> m && n != 0) {
    int a[n];
    R(i,0,n) {
      cin >> a[i];
    }
    int ans = 0, sum = 0;
    R(i,0,n-1) {
      R(j,i+1,n) {
        sum = a[i] + a[j];
        if (sum <= m) {
          ans = max(ans, sum);
        }
      }
    }
    if (ans != 0) {
      cout << ans << endl;
    } else {
      cout << "NONE" << endl;
    }
  }
}

C++: #include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<vector>
#include<list>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<cctype>
#include<climits>
#include<bitset>
#define ld long double
#define ll long long int
#define ull unsigned long long int
#define rep(i,n) for(i=0;i<n;i++)
#define fin(ans) cout<<(ans)<<endl
#define INF INT_MAX
#define vi vector<int>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pair<int,int> >
#define vvi vector<vector<int> >
#define vvc vector<vector<char> >
#define vvs vector<vector<string> >
#define P 1000000007
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;}
const long long LLINF=1LL<<60;
//set<int>::iterator it;
//|\_
//g++ -std=c++1z temp.cpp
//./a.out





int main(void){ios::sync_with_stdio(false);cin.tie(0);
//////////////////////////////////////////////////////
    int i,n,m,j;
    while(1){
        cin>>n>>m;
        if(n==0&&m==0)break;
        int maxcost=-1;
        vector<int> v(n,0);
        rep(i,n)cin>>v[i];
        for(i=0;i<n;i++){
            for(j=0;j<n;j++){
                if(i==j)continue;
                if(v[i]+v[j]<=m)maxcost=max(maxcost,v[i]+v[j]);
            }
        }
        if(maxcost>=0)cout<<maxcost<<endl;
        else cout<<"NONE"<<endl;
    }
//////////////////////////////////////////////////////
return 0;}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cctype>
#include <cstring>
typedef long long ll;
using namespace std;

int main()
{
    int n,m;
    cin>>n>>m;
    
    while(n>=2)
    {
        vector<int>s;
        int a;
        for(int i=0;i<n;i++)
        {cin>>a;
        s.push_back(a);}
        int sum=0;
        int max=0;
        for(int i=0;i<n;i++)
            for(int j=i+1;j<n;j++)
            {
                sum=s[i]+s[j];
                if(sum>max &&sum<=m)
                    max=sum;
            }
        if(max==0)
            cout<<"NONE"<<endl;
        else
            cout<<max<<endl;
        cin>>n>>m;
    }
    return 0;
}

C++: #include <bits/stdc++.h>
#define rep(i,a,b) for (int64_t i = (a); i < (b); i++)
#define REP(i,n) rep(i,0,n)
#define be(x) x.begin(),x.end()
using namespace std;
typedef long long ll;
int dx[]={1,-1,0,0,1,-1,1,-1};
int dy[]={0,0,1,-1,1,-1,-1,1};

int main()
{
    int n,m;
    while(cin>>n>>m)
    {
        if(n==0)return 0;
        vector<int>a(n);
        int maxx=0;
        REP(i,n)cin>>a[i];
        REP(i,n-1)
            rep(j,i+1,n)
            {
                int mix=a[i]+a[j];
                if(mix>m)continue;
                //if(mix==m){cout<<m<<endl;}
                maxx=max(mix,maxx);
            }
        if(maxx==0)cout<<"NONE"<<endl;
        else cout<<maxx<<endl;
    }
}

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

using namespace std;

int main(){

  int n=1,kakaku=1,min1,min2=1000000,a,b,c,i,j,k=0;
  vector<int> min3(50000,10000000);
 while(n!=0&&kakaku!=0){
   min2=1000000;
  cin>>n;
  vector<int> s(n);
  cin>>kakaku;

    for(i=0;i<n;i++){
      cin>>s.at(i);
    }

    for(i=0;i<n;i++){
      for(j=0;j<n;j++){
	if(i!=j){
	  a=s.at(i);
	  b=s.at(j);
	  c=a+b;
	  min1=kakaku-c;
	  if(min2>min1&&min1>=0){
	    min2=min1;
	    min3[k]=c;
	  }
	}
      }
    }
    k++;
 }
 for(i=0;i<k-1;i++){
   if(min3.at(i)==10000000){
      cout<<"NONE"<<endl;
    }else{
      cout<<min3.at(i)<<endl;
  }
 }
  return 0;
}

C++: #include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <utility>
#include <iomanip>

#define int long long int
#define rep(i, n) for(int i = 0; i < (n); ++i)

using namespace std;

typedef pair<int, int> P;

const int INF = 1e15;
const int MOD = 1e9+7;

signed main(){
    while(true){
        int n, m;
        cin >> n >> m;

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

        vector<int> a(n);
        rep(i, n) cin >> a[i];

        int ans = INF;
        rep(i, n){
            rep(j, n){
                if(i == j){
                    continue;
                }

                int tmp = a[i] + a[j];
                if(tmp > ans && tmp <= m){
                    ans = tmp;
                }
            }
        }
        if(ans == INF){
            cout << "NONE" << endl;
        }else{
            cout << ans << endl;
        }
    }

    return 0;
}