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 <vector>
using namespace std;
int main(int argc, char *argv[])
{
    for(;;) {
        int n, m;
        cin >> n >> m;
        if(n == 0 && m == 0) break;
        vector<int> is;
        for(int i = 0; i < n; i++) {
            int c;
            cin >> c;
            is.push_back(c);
        }
        int best = -1;
        for(int i = 0; i < n; i++) {
            for(int j = i+1; j < n; j++) {
                int k = is[i] + is[j];
                if( k <= m && k > best) best = k;
            }
        }
        if(best < 0) cout << "NONE" << endl;
        else cout << best << endl;
    }
    return 0;
}

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

using namespace std;

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

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

    vector<int> thing;
    for(int i = 0;i < n;++i){
      int much;
      cin>>much;

      thing.push_back(much);
    }

    sort(thing.begin(),thing.end(),greater<int>());
 
    int i = 0;
    int j = 0;
    int sum = 0;

    for(int e : thing){
      for(int f : thing){
        if(e + f <= m && i != j && sum < e + f){
          sum = e + f;
        }
        ++j;
      }
      j = 0;
      ++i;
    }
    if(sum != 0){
      cout<<sum<<endl;
    }
    else{
      cout<<"NONE"<<endl;
    }
  }

  return 0;
}

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

using namespace std;

int v[10001];

int main() {
    int num_elems, max_price;
    cin >> num_elems >> max_price;
    do {
        int best = -1;
        bool best_initialized = false;
        int x;
        for (int i = 0; i < num_elems; i++) {
            cin >> x;
            v[i] = x;
        }

        sort(v, v + num_elems);

        int j = num_elems - 1;
        for (int i = 0; i < num_elems; i++) {
            while(j > i && v[i] + v[j] > max_price) {
                j--;
            }

            if(j > i && (!best_initialized || v[i] + v[j] > best)) {
                best = v[i] + v[j];
                best_initialized = true;
            }
        }

        if (best_initialized) {
            cout << best << '\n';
        }
        else {
            cout << "NONE\n";
        }

        cin >> num_elems >> max_price;
    }while(num_elems != 0);

    return 0;
}

C++: #include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <string.h>
#include <algorithm>
#include <cmath>
#include <limits>
#include <sstream>

using namespace std;

int main (void)
{
	for (long long u = 0; u < 50000; u++)
	{
		long long n,m,a[1001];
		cin >> n >> m;
		if (n == 0 && m == 0)
		{
			break;
		}
		int p = 0;
		int o = 0;

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

		sort(a,a + n);

		for (int i = 0; i < n; i++)
		{
			for (int j = 1; j < n; j++)
			{
				if (i < j && a[i] + a[j] <= m)
				{
					if (p < a[i] + a[j])
					{
						p = 0;
						p = a[i] + a[j];
					}
				}
				else if (a[i] + a[j] > m)
				{
					break;
				}
			}
			if (p == 0 && i == n - 1)
			{
				cout << "NONE" << endl;
				o = -1;
			}
		}

		if (o != -1)
		{
			cout << p << endl;
		}
	}
}

C++: #include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i = (a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
const ll INF = 1e9+100;
const ll MOD = 1e9+7;

int n, m;
int a[1000];

int main() {
	while (cin >> n >> m, n || m) {
		REP(i, n) scanf("%d", a + i);
		sort(a, a + n);
		int ans = -1;
		REP(i, n) {
			int sum = a[i] + *(upper_bound(a, a + n, m - a[i]) - 1);
			if (sum < m) chmax(ans, sum);
		}
		if (ans == -1) puts("NONE");
		else printf("%d\n", ans);
	}
	
	return 0;
}

C++: #include<iostream>
#include<vector>
using namespace std;
int main(){
  vector<int> a(1000);
  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[i]=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";
    }else if(n!=0&&m!=0){
      cout<<max<<"\n";
    }
  }
}

C++: /*Problem sennobushige 16D8104015E 18.5.16*/
#include <iostream>
#define N 1000000

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


  for(int l=0;l<N;l++){
    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";
    }
   
  }



}