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;

#define int long long

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int N, M;
  while ( cin >> N >> M, N ) {

    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++ ) {
	if ( i == j ) continue;	
	if ( a[i]+a[j] <= M ) ans = max(ans, a[i]+a[j]);
      }
    }

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

C++: #include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  while (true) {
    int n, m; cin >> n >> m;
    if (!n) break;
    V<> a(n); for (auto&& e : a) cin >> e;
    int res = -1;
    for (int i = 0; i < n; ++i) for (int j = 0; j < i; ++j) {
      if (a[i] + a[j] <= m) res = max(res, a[i] + a[j]);
    }
    cout << (res != -1 ? to_string(res) : "NONE") << '\n';
  }
}

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

int main () {
  int n=1,m=1;
  int j[10000],jc=0;
  int max,tmp;
  while(n>0 and m>0){
    std::cin>>n>>m;
    if(n==0 and m==0) break;
    int s[n];
    max=0;
    for(int i=0;i<n;i++){
      std::cin>>s[i];
    }
    for(int k1=0;k1<n;k1++){
      for(int k2=k1+1;k2<n;k2++){
	tmp=s[k1]+s[k2];
	if(max<tmp and tmp<=m){
	  max=tmp;
	}
      }
    }
    j[jc]=max;
    jc++;
  }
  for(int i=0;i<jc;i++){
    if(j[i]==0){
      std::cout<<"NONE\n";
    }else{
      std::cout<<j[i]<<'\n';
    }
  }

  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" << "\n";return true;}
    cout << tempMax << "\n";return true;
}

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

C++: #include "bits\stdc++.h"
using namespace std;
int main() {
	int a[1000];
	int n, m;
	while (cin >> n >> m, n) {
		for (int i = 0; i < n; i++) {
			cin >> a[i];
		}
		int ans = 0;
		for (int i = 0; i < n; i++) {
			for (int j = i + 1; j < n; j++) {
				if (a[i] + a[j] <= m) ans = max(ans, a[i] + a[j]);
			}
		}
		if (ans == 0) cout << "NONE" << endl;
		else cout << ans << endl;
	}
}

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

int n, m;
int a[1000];

int main() {
	
	while (cin >> n >> m) {
		if (!n) break;
		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++) {
				if (a[i] + a[j] <= m) {
					ans = max(ans, a[i] + a[j]);
				}
			}
		}
		
		if (ans == -1) { cout << "NONE" << endl; }
		else { cout << ans << endl; }
	}
	return 0;
}

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

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

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

int up_bound(vector<int> &A, int x) // A[i] <= xとなる最大のiを求める
{
    int ok = -1;
    int ng = A.size();
    while(abs(ok-ng)>1) {
        int mid = (ok + ng)/2;
        if(A[mid] <= x) ok = mid;
        else ng = mid;
    }
    return ok;
}

bool solve() {
    int n, m;
    cin >> n >> m;
    if(n == 0 && m == 0) return false;

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

    sort(a.begin(), a.end());
    //for(auto &p : a) cout << p << " ";
    //cout << endl;
    int res = -1;

    // 尺取りか二分探索
    for(int i = 0; i < n; ++i) {
        if(a[i] >= m) continue;
        int j = up_bound(a, m - a[i]);
        if(i >= j) continue;
        //cout << i << " " << j << endl;
        res = max(res, a[i] + a[j]);
    }

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

    return true;
}

int main() {
    while(solve()) ;
    return 0;
}

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

const int INF = 2e9+7;

int solve(int arr[],int N,int M){
	int ret=0,temp;
	for(int i=0;i<N;i++){
		for(int j=i+1;j<N;j++){
			temp=arr[i]+arr[j];
			if(temp<=M) ret=max(ret,temp);
		}
	}
	
	return ret;
}

int main(){
	int N,M;
	while(1){
		cin>>N>>M;
		if(!N&&!M) break;
		int arr[N];
		for(int i=0;i<N;i++) cin>>arr[i];
		int ans=solve(arr,N,M);
		if(ans==0) cout<<"NONE";
		else cout<<ans;
		cout<<"\n";
	}
	return 0;
}

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

int main() {
	int n, m;
	while (1) {
		cin >> n >> m;
		if (n == 0 && m == 0)
			break;
		vector<int> price;
		for (int i = 0; i<n; i++) {
			int x;
			cin >> x;
			if (x < m)
				price.push_back(x);
		}

		int max = 0;
		for (int i = 0; i<price.size(); i++) {
			for (int j = i + 1; j<price.size(); j++) {
				int sum = price[i] + price[j];
				if (sum <= m && sum >= max) {
					max = sum;
				}
			}
		}
		if (max != 0)
			cout << max << endl;
		else cout << "NONE" << endl;
	}
	return 0;
}