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 <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
#define all(x) x.begin(),x.end()
#define let auto const

int main() {
  i64 n, m;
  while(cin >> n >> m, n) {
    vector<i64> a(n);
    rep(i,0,n) cin >> a[i];
    sort(all(a));
    i64 ans = 0;
    for(auto iter = begin(a); iter != end(a); ++iter) {
      auto ui = upper_bound(all(a), m - *iter);
      if(ui == begin(a)) continue;
      --ui;
      if(ui == iter) {
        if(ui == begin(a)) continue;
        --ui;
      }

      ans = max(ans, *ui + *iter);
    }
    if(ans == 0) {
      cout << "NONE" << endl;
    }
    else {
      cout << ans << endl;
    }
  }
}

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

using namespace std;

int main()
{
    while (true) {
        int n;
        int m;
        cin >> n >> m;
        if (n == 0 && m == 0) {
            break;
        }

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

        int r = -1;
        for (int i = 0; i < n; ++i) {
            for (int j = 0; j < n; ++j) {
                if (i == j) {
                    continue;
                }
                auto a = v[i] + v[j];
                if (a <= m) {
                    r = max(a, r);
                }
            }
        }
        if (r == -1) {
            cout << "NONE" << endl;
        }
        else {
            cout << r << endl;
        }
    }
}

C++: #include <iostream>

using namespace std;

int main() {
    int a[1001];
    int n, m;
    while (cin >> n >> m) {
        if (n == 0 && m == 0) { break; }
        for (int i = 0; i < n; i++) {
            cin >> a[i];
        }
        int ans = -1;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if (a[i] + a[j] <= m && a[i] + a[j] > ans) {
                    ans = a[i] + a[j];
                }
            }
        }
        if (ans == -1) { cout << "NONE" << endl; }
        else { cout << ans << endl; }
    }
    return 0;
}

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

bool q1(){
    int n,maxValue;
    cin >> n >> maxValue;
    if(n==0 && maxValue==0)return false;
    int value[n];
    int tempValue=0;
    int tempMax=0;
    for(int i=0;i<n;i++){
        cin >> value[i];
    }
    for(int top=0;top<n-1;top++){
    for(int i=1;i<n-top;i++){
        tempValue = value[top] + value[top+i];
        if(tempMax < tempValue && tempValue <= maxValue)tempMax=tempValue;
    }
    }
    if(tempMax==0){cout << "NONE";return true;}
    cout << tempMax << "\n";return true;
}

int main()
{
    while(q1());
}

C++: #include <algorithm>
#include <cstring>
#include <cmath>
#include <cstdio>

using namespace std;

const int MAX_N = 1005;
int arr[MAX_N];

int main() {
    int n, m;
    scanf("%d%d", &n, &m);
    while (n != 0) {
        for (int i = 0; i < n; ++i) {
            scanf("%d", arr + i);
        }
        sort(arr, arr + n);
        int sum = 0;
        for (int i = n - 1; i >= 0; i--) {
            if (arr[i] >= m) continue;
            int rem = m - arr[i];
            int p = (int) (lower_bound(arr, arr + i, rem) - arr);
            if (arr[p] != rem)
                p--;
            if (p >= 0 && p != i)
                sum = max(sum, arr[p] + arr[i]);
        }
        if (sum == 0)
            printf("NONE\n");
        else
            printf("%d\n", sum);
        scanf("%d%d", &n, &m);
    }
    return 0;
}

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


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


  while(n!=0){
    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";
    }
   
  }



}

C++: #include <iostream>
#define MAX 1001
using namespace std;
int a[MAX];

int main(){
    while(true){
        int n,m,maxsum = 0;
        cin >> n >> m;
        if(n == 0 && m == 0)break;

        for(int i = 0;i < n;i++)
            cin >> a[i];
        
        for(int i = 1;i < n -1;i++){
            for(int j = i + 1;j < n;j++){
                if((a[i] + a[j] <= m))
                    maxsum = max(maxsum,a[i] + a[j]);
            }
        }

        if(maxsum == 0)
            cout << "NONE" << endl;
        else
            cout << maxsum << endl;
    }

    return 0;
}