Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var scanner = bufio.NewScanner(os.Stdin)

func main() {
	for scanner.Scan() {
		n, _ := strconv.Atoi(scanner.Text())
		if n == 0 {
			break
		}

		sales := make([]int, 4000)
		members := make([]int, 0)
		memberCheck := make(map[int]bool)

		for i := 0; i < n; i++ {
			scanner.Scan()
			input := strings.Split(scanner.Text(), " ")
			e, _ := strconv.Atoi(input[0])
			p, _ := strconv.Atoi(input[1])
			q, _ := strconv.Atoi(input[2])

			if e >= 1 && e <= 4000 && memberCheck[e] == false {
				members = append(members, e)
				memberCheck[e] = true
			}
			sales[e-1] += p * q
		}

		emptyFlag := true
		for _, v := range members {
			if sales[v-1] >= 1000000 {
				fmt.Println(v)
				emptyFlag = false
			}
		}

		if emptyFlag == true {
			fmt.Println("NA")
		}
	}
}

C++: #include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctype.h>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define F(i,j,k) fill(i[0],i[0]+j*j,k)
#define P(p) cout<<(p)<<endl;
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define INF 1<<25
#define MAX 100000000
#define pb push_back
using namespace std; 
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<double> vd;
typedef pair<int,int> pii;
typedef pair<long,long> pll;
typedef long long ll;
  
int main(){
  int n;
  while(1){
    cin >> n;
    if(n == 0) break;
    int p[4001];
    for(int i = 0;i < 4001;i++){
      p[i] = 0;
    } 
    for(int i = 0;i < n;i++){
      int b,t,s;
      cin >> b >> t >> s;
      p[b] += t*s;
    }
    int count = 0;
    for(int i = 1;i < 4001;i++){
      if(p[i] >= 1000000){
	P(i);
	count++;
      }
    }
    if(count == 0){
      P("NA");
    }
  }
  return 0;
}

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

static const long long TOTAL_NORMA = 1000000;
static const int MAX_WORKER_SIZE = 4000;
static long long m[MAX_WORKER_SIZE];
static bool isShow[MAX_WORKER_SIZE];


int main(void) {
    int n;

    while (std::cin >> n) {
        if (n == 0) {
            return 0;
        }

        // init
        bool f = true;
        std::fill(m, m + (sizeof m / sizeof m[0]), 0);
        std::fill(isShow, isShow + (sizeof isShow / sizeof isShow[0]), false);

        for (int i = 0; i < n; ++i) {
            long long number, price, quantity;
            std::cin >> number >> price >> quantity;

            m[number] += (price * quantity);

            if (isShow[number] == false && TOTAL_NORMA <= m[number]) {
                std::cout << number << std::endl;
                isShow[number] = true;
                f = false;
            }
        }

        if (f) {
            std::cout << "NA" << std::endl;
        }

    }

    return 0;
}

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

int main()
{
    while(1)
    {
        int n;
        cin>>n;
        if(n==0) return 0;
        multimap< int,int,greater<int> > sr;
        for(int i=0;i<n;++i)
        {
            int sn,p,q;
            cin>>sn>>p>>q;
            sr.insert(make_pair(sn,p*q));
        }
        multimap<int,int>::iterator it=sr.begin();
        do{
            if(it==sr.begin()&&(*it).second<1000000) {
                cout<<"NA"<<endl;  break;
            }
            cout<<(*it).first<<endl;
            ++it;
        }while((*it).second>=1000000);
    }
}

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

int main() {
  while(1) {
    int n;
    cin >> n;
    if(n == 0) break;

    map<int, int> data;
    map<int, bool> flag;
    int cnt = 0;
    for(int i = 0; i < n; i++) {
      int id, p, num;
      cin >> id >> p >> num;
      for(int j = 0; j < num; j++) {
	data[id] += p;
	if(data[id] >= 1000000 && !flag[id]) {
	  cout << id << endl;
	  flag[id] = true;
	  cnt++;
	  break;
	}
      }
    }
    if(cnt == 0) cout << "NA" << endl;
  }
  return 0;
}

C++: #include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int dx[] = { -1, 0, 1, 0 }; const int dy[] = { 0, 1, 0, -1 };
struct salary{
	int no;
	long long sell;
	bool b;
};

int main() {
	
	int n;
	while(cin>>n,n){
		vector<salary> vs;
		REP(i, n){
			int no, sell_n, value;
			cin >> no >> sell_n >> value;
			bool b = false;
			REP(j, vs.size()){
				if (vs[j].no == no){
					b = true;
					vs[j].sell += sell_n*value;
					
				}
			}
			if (!b)vs.push_back({ no, sell_n*value ,false});
			REP(j, vs.size()){
				if (vs[j].sell >= 1000000){
					vs[j].b = true;
				}
			}
		}
		bool b2=false;
		REP(i, vs.size()){
			if (vs[i].b){
				cout << vs[i].no << endl;
				b2 = true;
			}
		}
		if (!b2)cout << "NA"<< endl;
	}
}

C++: #include "stdio.h"
#include "string.h"
long long N[4001];
int f[4001];
int main(){
    int x,n,p,i,j,c=0;
    scanf("%d",&i);
    while(i!=0){
        c=0;
        for(j=0;j<i;j++){
            scanf("%d%d%d",&x,&n,&p);
            if(N[x]>=0){
                N[x]+=n*p;
                if(N[x]>=1000000){
                    f[c]=x;
                    c++;
                    N[x]=-1;
                }
            }
        }
        if(c==0)
            printf("NA\n");
        else 
            for(j=0;j<c;j++)printf("%d\n",f[j]);
        memset(N,0,4001);
        memset(f,0,4001);
        scanf("%d",&i);
    }
    return 0;
}

C++: #include <stdio.h>

int output[50000];
int count=0;

void input(int);
int main(void){
	int n,i;
	while(true){
		scanf("%d",&n);
		if(n>0){
			input(n);
		}else{
			break;
		}
	}
	for(i=0;i<count;i++){
		if(output[i]!=0){
			printf("%d\n",output[i]);
		}else{
			printf("NA\n");
		}
	}
	
	return 0;
}
void input(int n){
	int e[4000];
	int p[1000000];
	int q[100000];
	int c[n];
	
	int i;
	
	for(i=0;i<n;i++){
		scanf("%d",&e[i]);
		scanf("%d",&p[i]);
		scanf("%d",&q[i]);
		c[i] = p[i]*q[i];
	}
	
	int j;
	
	for(i=0;i<n-1;i++){
		for(j=1;j<n;j++){
			if(e[i]==e[j]){
				c[i]=c[i]+c[j];
				c[j]=0;
			}
		}
	}
	int ch = 0;
	
	for(i=0;i<n-1;i++){
		if(c[i]>=1000000){
			output[count]=e[i];
			count++;
			ch = 1;
		}
	}
	if(ch == 0){
		output[count]=0;
		count++;
	}
}