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 ll = long long;
template<class T> using vt = vector<T>;
template<class T> using vvt = vector<vt<T>>;
template<class T> using ttt = tuple<T,T>;
using tii = tuple<int,int>;
using vi = vector<int>;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define mt make_tuple
#define ALL(a) (a).begin(),(a).end()
#define FST first
#define SEC second
#define DEB cerr<<"!"<<endl
#define SHOW(a,b) cerr<<(a)<<" "<<(b)<<endl
#define DIV int(1e9+7)
const int INF = (INT_MAX/2);
const ll LLINF = (LLONG_MAX/2);
const double eps = 1e-8;
//const double PI = M_PI;
inline ll pow(ll x,ll n,ll m){ll r=1;while(n>0){if((n&1)==1)r=r*x%m;x=x*x%m;n>>=1;}return r%m;}
inline ll lcm(ll d1, ll d2){return d1 / __gcd(d1, d2) * d2;}
#define chmax(a,b) a=max(a,b)

/*Coding Space*/
int main(){
  int n,m;
  while(cin >> n >> m, n){
    int ans = 0;
    vi a(n);
    rep(i,n)  cin >> a[i];
    rep(i,n)rep(j,n){
      if(i != j && m - ans >= m - a[i] - a[j] && m >= a[i] + a[j])
        ans = max(ans,a[i] + a[j]);
    }
    if(ans == 0)  cout << "NONE" << endl;
    else  cout << ans << endl;
  }
}

C++: #include <cstdio>
#include <algorithm>
using namespace std;
int N,M;
int a[1010];

int main () {
	while(1) {
		int pri = -1;
		scanf("%d%d",&N,&M);
		if(N == 0 && M == 0) break;
		for(int i = 1;i <= N;++i) {
            scanf("%d",&a[i]);
		}
		sort(a + 1,a + 1 + N);
		for(int i = 1;i < N;++i) {
            int t = upper_bound(a + i + 1,a + N + 1,M - a[i]) - a;
			if(t == i || t == i + 1)
				break;
			if(a[i] + a[t - 1] > pri)
				pri = a[i] + a[t - 1];
		}
		if(pri != -1)
			printf("%d\n",pri);
		else printf("NONE\n");
	}
}

C++: #include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int n,m;
int a[1000];
main()
{
while(cin>>n>>m,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(a[i]+a[j]<=m&&ans<a[i]+a[j])ans=a[i]+a[j];
if(ans>=0)cout<<ans<<endl;
else cout<<"NONE"<<endl;
}
}

C++: #include <bits/stdc++.h>

using namespace std;

int main()
{
	int n, m;
	while (cin >> n >> m, n)
	{
		vector<int> v(n);
		for (int i = 0; i < n; ++i)
		{
			cin >> v[i];
		}
		int ma = 0;
		for (int i = 0; i < n; ++i)
		{
			for (int j = i + 1; j < n; ++j)
			{
				if (v[i] + v[j] > m)
					continue;
				if (ma < v[i] + v[j])
				{
					ma = v[i] + v[j];
				}
			}
		}
		if (ma == 0)
			cout << "NONE" << endl;
		else
			cout << ma << endl;
	}
}

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

int main()
{
  int n, m, MAX = 0, SUM;
  int a, size;
  vector<int> v;

  while(cin >> n >> m, n) {

    int MAX = 0, SUM, a, size;
    vector<int> v;

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

    for (int i = 0; i < v.size(); i++) {
      for (int j = i+1; j < v.size(); j++) {
	SUM = v[i] + v[j];
	if (SUM <= m) {
	  MAX = max(MAX, SUM);
	  //cout << MAX << endl;
	}
      }
    }
    
    if (MAX==0) {
      cout << "NONE" << endl;
    }
    else {
      cout << MAX << endl;
    }
    
  }
  
  return 0;
}

C++: #include<iostream>
int maxs(int n,int m,int a[]){
  int maxs=0,flag=0;
  for(int i=0;i<n;i++){
    for(int j=i+1;j<n;j++){

      if(maxs<a[i]+a[j]){
	if(a[i]+a[j]<=m){
	  maxs=a[i]+a[j];
	  flag=1;
	}
      }

    }
  }

  if(flag==1){
    return maxs;
  }else{
    return -1;
  }
}


int main(){

  int n,m,count=0;
  int  b[50000];
  while(n!=0&&m!=0){
    std::cin>>n;
    std::cin>>m;
    if(n==0&&m==0){
      break;
    }
    int a[n];
    for(int i=0;i<n;i++){
      std::cin>>a[i];
    }
    b[count]=maxs(n,m,a);
    count++;
  }
  for(int i=0;i<count;i++){
    if(b[i]==-1){
      std::cout<<"NONE"<<"\n";
    }else{
    std::cout<<b[i]<<"\n";
    }
  }

  return 0;
}

C++: #include <iostream>

int main(void){
  while(1){
    int n , m;
    cin >> n;
    cin >> m;
    if(n == 0 && m == 0){
      return 0;
    }

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

    int sum[n][n];

    for(int i = 0 ; i < n ; i ++){
      for(int j = 0 ; j < n ; j++){
        if(i != j){ sum[i][j] = a[i] + a[j]; }
        else{ sum[i][j] = -1000; }
      }
    }

    int max = -1000;

    for(int i = 0 ; i < n ; i++){
      for(int j = 0 ; j < n ; j++){
        if( sum[i][j] > max && sum[i][j] < m ){
          max = sum[i][j];
        }
      }
    }

    if(max == -1000){
      cout << "NONE" << endl;
    }else{
      cout << max;
    }
  }

}

C++: #include <iostream>
#define N 50000

int main(){
  int n=1,max;
  int A[N]={0},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";
    }
   
  }



}