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 <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;

void Sort(int *x, int *y);

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

    for(int i=1;i<n;i++){
        int j=i-1;

        int min=a[i];

        while(j>=0 && a[j]>min){
            swap(a[j],a[j+1]);
            j--;
        }
    }
    
    int sum=0;
    for(int i=n-1;i>0;i--){
        for(int j=i-1;j>=0;j--){
            //cout<<"a[i]="<<a[i]<<":"<<"a[j]="<<a[j]<<endl;

            if((a[i]+a[j])<=m && a[i]+a[j]>sum){
                sum = a[i]+a[j];
            }
        }
    }

    if(sum>0)cout<<sum<<endl;
    else cout<<"NONE"<<endl;

    return 0;
}


void Sort(int *x,int *y){
    int hoge;
    hoge=*x;
    *x=*y;
    *y=hoge;
}

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


using namespace std;

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

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

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

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

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

		int sum = -1;

		for(int i=0; i<n-1; i++){
			for(int j=i+1; j<n; j++){
				int p = a[i]+a[j];

				if(p<=m && p>sum){
					sum = p;
				}
			}
		}

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

	return 0;
}

C++: #include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cassert>
#include <string>
#include <algorithm>
#include <vector>
#include <valarray>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <iomanip>
#include <map>
#include <set>
#include <list>
#include <limits>
#include <numeric>
#include <utility>
#include <deque>
#include <unordered_set>
#include <unordered_map>
#include <regex>
#include <array>
#include <bitset>
#include <complex>
#include <tuple>
#include <random>

using namespace std;
using ll = long long;
const int INF = 1e9;
const ll MOD = 1e9 + 7;

int main()
{
  int n, m;
  while (cin >> n >> m, n || m)
  {
    vector<int> a(n);
    for (auto &e : a)
      cin >> e;
    int ans = -1;
    for (int i = 0; i < n; ++i)
    {
      for (int j = i + 1; j < n; ++j)
      {
        if (i == j)
          continue;
        if (ans < a[i] + a[j] && a[i] + a[j] <= m)
          ans = a[i] + a[j];
      }
    }
    if (ans == -1)
      cout << "NONE" << endl;
    else
      cout << ans << endl;
  }

  return 0;
}

C++: #include <iostream>
#include <vector>
#include <queue>
using namespace std;
typedef vector<int> intvec;
typedef queue<int> intqueue;


void quicksort(int v_id, int v_l, intvec &vec) {
  intqueue small, big;
  int N = v_l - v_id;
  int N_big = 0;
  int pivot = vec[v_id];
  for(int i = v_id + 1; i < v_l; i++){
    if(pivot <= vec[i]){
      big.push(vec[i]);
      N_big++;
    }
    else small.push(vec[i]);
  }

  for (int i = v_id; i < v_id + N_big; i++){
    vec[i] = big.front();
    big.pop();

  }
  vec[v_id+N_big] = pivot;
  for (int i = v_id + 1 + N_big; i < v_l; i++){
    vec[i] = small.front();
    small.pop();

  }


  if( N_big > 1){
    quicksort(v_id, v_id + N_big, vec);
  }
  if (N_big < N-1){
    quicksort(v_id + N_big + 1, v_l, vec);
  }
}

int main(){
int N,M;

while(1){
  int value = 0, buf;
  cin >> N >> M;
  intvec vec(N);
  if(N==0&&M==0) break;
  for(int i = 0; i < N; i++){
    cin >> vec[i];
  }
  quicksort(0,N,vec);
  for (int i=0; i<N; i++){
    for (int j = i+1; j<N; j++){
      buf = vec[i] + vec[j];
      if(buf == M){
        value = buf;
        i=N-1;
        j=N-1;
      }

      else if(buf < M){
        if(value < buf) value = buf;
        break;
      }
    }
  }
  if(value == 0) cout << "NONE" << endl;
  else cout << value << endl;
}
}

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

signed
main(){
		int n,m;
		while(cin >> n >> m && !(n==0 && m==0))
		{
				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++)
						{
						int key = a[i] + a[j];
						if(key <= m)
						{
						if(ans<key)
						ans = key;
						}
						}
				}

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