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> 
#define LL long long
#define MOD 1e9+7
#define pi acos(-1.0)
#define ULL unsigned long long
#define mem_1(str) memset(str,-1,sizeof(str))
#define mem0(str) memset(str,0,sizeof(str))
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
using namespace std;
const int maxn = 110;
const int INF = 0x3f3f3f3f;
int num[1005];
int main()
{
	int n,sum;
	while(scanf("%d%d",&n,&sum))
	{
		int ans=-1;
		if(n==0&&sum==0) break;
		else 
		{
			int k=0;
			for(int i=1;i<=n;i++)
			{
				scanf("%d",&num[i]);
			}
			for(int i=1;i<=n;i++)
			{
				for(int j=i+1;j<=n;j++)
				{
					if(num[i]+num[j]<=sum)
					{
						ans=max(num[i]+num[j],ans);
					}
				}
			}
			if(ans==-1) printf("NONE\n");
			else
		printf("%d\n",ans);
	    }
		
	}

	return 0;
}

C++: #include <iostream>
#define MAX 1000
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;j < n;j++){
                if((a[i] + a[j] <= m))
                    maxsum = max(maxsum,a[i] + a[j]);
            }
        }

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

    return 0;
}

C++: #include<iostream>
#include<vector>
using namespace std;
int main(){
  int i,n,m,j;
  vector<int> ans;
  while(1){
    cin>>n>>m;
    if(n==0 && m==0) break;
    vector<int> item(n);
    for(i=0; i<n; i++){
      cin>>item[i];
    }
    int max=0;
    int sum;
    for(i=0; i<n; i++){
      for(j=i+1; j<n; j++){
	sum=0;
	sum=item[i]+item[j];
	if(sum>max && sum<m+1){
	  max=sum;
	}
      }
    }
    if(max==0){
      ans.push_back(-1);
    }else{
    ans.push_back(max);
    }
  }
  for(i=0; i<ans.size(); i++){
    if(ans[i]==-1){
      cout<<"NONE";
    }else{
      cout<<ans[i];
    }
    cout<<endl;
  }
  cout<<endl;
  return 0;
}

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

using namespace std;

int main(){

  int n=1,kakaku=1,min1,min2=1000000,a,b,c,i,j,k=0;
  vector<int> min3(50000,10000000);
  while(n!=0&&kakaku!=0){
    min2=1000000;
    cin>>n;
    vector<int> s(n);
    cin>>kakaku;

    for(i=0;i<n;i++){
      cin>>s.at(i);
    }

    for(i=0;i<n;i++){
      for(j=0;j<n;j++){
	if(i!=j){
	  a=s.at(i);
	  b=s.at(j);
	  c=a+b;
	  min1=kakaku-c;
	  if(min2>min1&&min1>=0){
	    min2=min1;
	    min3[k]=c;
	  }
	}
      }
    }
    k++;
  }
  for(i=0;i<k-1;i++){
    if(min3.at(i)==10000000){
      cout<<"NONE"<<endl;
    }else{
      cout<<min3.at(i)<<endl;
    }
  }
  return 0;
}

C++: #include <iostream>
using namespace std;
int main(void)
{
	int n, m;
	int a[1001];
	while (cin >> n >> m) {
		if (n == 0 && m == 0)	break;
		for (int i = 0; i < n; i++) {
			cin >> a[i];
		}
		int max = 0;
		int x;
		for (int i = 0; i < n; i++) {
			for (int j = i + 1; j < n; j++) {
				x = a[i] + a[j];
				if (x > max && x <= m)	max = x;
			}
		}
		if (max == 0) {
			cout << "NONE" << endl;
		}
		else {
			cout << max << endl;
		}
	}


	return 0;
}

C++: 

#include<iostream>
using namespace std;

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

C++: #include <cstdio>
#include <algorithm>
using namespace std;
int arr[1001];

int main()  {

    int n, m, idx, diff, sum = 0;
    for (;;) {
        scanf("%d %d", &n, &m);
        if (n == 0 && m == 0) break;
        sum = 0;
        fill(arr, arr+n, 0);
        for (int i = 0; i < n; i++) scanf("%d", &arr[i]);
        sort(arr, arr+n);
        for (int i = n - 1; i >= 1; i--) {
            if (arr[i] > m) continue;
            idx = int(upper_bound(arr, arr+i, m-arr[i]) -arr-1);
            if (arr[i] + arr[idx] <= m && idx != i && idx >= 0 ) sum = max(sum, arr[i]+arr[idx]);
            if (sum == m) break;
        }
        (sum == 0) ? printf("NONE\n") : printf("%d\n", sum);
    }
    return 0;
}

C++: #include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
typedef long long int ll;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000001
using namespace std;


int main(){

	int N,M,maximum,table[1000];

	while(true){
		scanf("%d %d",&N,&M);
		if(N == 0 && M == 0)break;

		maximum = 0;

		for(int i = 0; i < N; i++)scanf("%d",&table[i]);

		for(int i = 0; i < N-1; i++){
			for(int k = i+1; k < N; k++){
				if(table[i]+table[k] <= M){
					maximum = max(maximum,table[i]+table[k]);
				}
			}
		}

		if(maximum == 0){
			printf("NONE\n");
		}else{
			printf("%d\n",maximum);
		}
	}

	return 0;
}