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<iostream>
using namespace std;
long long t[4000],z,b,c;
int n,a,s[4000],u[4000],cnt;
void change(int x,int y){
  int tmp;
  long long TMP;
  TMP=t[x];t[x]=t[y];t[y]=TMP;
  tmp=s[x];s[x]=s[y];s[y]=tmp;
  tmp=u[x];u[x]=u[y];u[y]=tmp;
}
void init(){
  for(int i=0;i<4000;i++){
    t[i]=0;
    s[i]=u[i]=4001;
  }
  cnt=0;
}
int main(){
  while(1){
    cin>>n;
    if(n==0)break;
    init();
    for(int i=0;i<n;i++){
      cin>>a>>b>>c;
      a--;
      u[a]=a;
      z=b*c;
      t[a]=t[a]+z;
      if(s[a]==4001)s[a]=i;
    }
    for(int i=3999;i>0;i--){
      for(int j=0;j<i;j++){
	if(s[j]>s[j+1]){
	  change(j,j+1);
	}
      }
    }
    for(int i=3999;i>0;i--){
      for(int j=0;j<i;j++){
	if(t[j]<t[j+1]){
	  change(j,j+1);
	}
      }
    }
    cnt=0;
    for(int i=0;i<4000;i++){
      if(t[i]>=1000000){
	cout<<u[i]+1<<endl;
	cnt=1;
      }else{
	break;
      }
    }
    if(cnt==0)cout<<"NA"<<endl;
    
  }
  
}

C++: #include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <map>
#include <set>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#define rep(i,l,n) for(lint i=l;i<n;i++)
#define rer(i,l,n) for(lint i=l;i<=n;i++)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define pb(a) push_back(a)
#define mk(a,b) make_pair(a,b)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef vector<int> vi;
typedef vector<lint> vli;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

int main(){
	while (1){
		queue<int> q;
		lint d[4010] = {};
		int n;
		cin >> n;
		if (n == 0) break;
		int a, b, c;
		rep(i, 0, n){
			cin >> a >> b >> c;
			if (d[a] == 0){
				q.push(a);
			}
			d[a] += b*c;
		}
		int ct = 0;
		while (!q.empty()){
			int x = q.front(); q.pop();
			if (d[x] >= 1000000){
				o(x); ct++;
			}
		}
		if (ct == 0){
			o("NA");
		}
	}

}

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

template<typename itr, typename func>
func for_each_withindex(itr fi, itr l, func f){
	unsigned i{};
	for(; fi!=l; ++fi,++i){
		f(*fi,i);
	}
	return f;
}

int main(int argc, char const* argv[])
{
	unsigned n{};
	while (std::cin >> n,n != 0) {
		long long e{}, p{}, q{};
		bool isna{true};
		std::array<long long,4001> es{};
		for (unsigned i = 0; i < n; i++) {
			std::cin >> e >> p >> q;
				es.at(e) += p * q;
		}
		for_each_withindex(es.begin(), es.end(), [&isna](long long sell,long long e){ 
				if (sell>=1000000) {
				std::cout << e << std::endl;
				isna = false;
				}});
		if (isna) {
			std::cout << "NA" << std::endl;
		}

	}
	return 0;
}

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

int main(){
    int n;
    
    while(true){
        int cnt = 0;
        unsigned long long int s[4002]={0},gs[4002]={0};
        
        cin >> n;
        if(!n) break;
        
        int t,cost;
        int num;
        for(int i = 0 ; i < n ; i++){
            cin >> num >> t >> cost;
            s[num] += t*cost;
            gs[i] = num;
        }
        
       for(int i = 0 ; i < n ; i++){
            for(int j = i+1 ; j < n ; j++){
                if(gs[i]==gs[j]&&i < j){
                    gs[j] = 4001;
                }
            }
        }
        
        for(int i = 0 ; i < n ; i++){
            if(s[gs[i]] >= 1000000){
                cout << gs[i] << endl;
                cnt++;
            }
        }
        if(!cnt) cout << "NA" << endl;
    }
    
    return 0;
}

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

int main()
{
	int n,id,sale,k,cnt;
	int outid[4001];
	while (1)
	{
		cin >> n;
		if (n == 0)break;
		cnt = 0;
		for (int i = 0; i < n; i++)
		{
			cin >> id >> sale >> k;
			if (sale*k >= 1000000)
			{
				cnt++;
				outid[cnt] = id;
			}
		}
		if (cnt==0)
		{
			cout << "NA" << endl;
		}
		else
		{
			for (int i = 1; i <= cnt; i++)
			{
				cout << outid[i] << endl;
			}
		}
	}
	return 0;
}

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




int main(){
	int n;
	cin >> n;

	while(n != 0){
		vector < pair<long, long> > v(n);
		int num = 0;
		for (int i = 0; i < n; ++i){
			long long id, p, q;
			cin >> id >> p >> q;
			v[i] = make_pair(id, p * q);
		}

		sort(v.begin(), v.end());
		long long sum = v[0].second;

		for(int i = 1; i < n ; i++){
			if(v[i].first == v[i-1].first){
				if(i + 1 != n){
					sum += v[i].second;

				}else{
					sum += v[i].second;
					if(sum >= 1000000){
						cout << v[i].first << endl;
						num++;
					}
				}
			}else{
				if(sum >= 1000000){
					cout << v[i-1].first << endl;
					num++;
				}
				sum = v[i].second;
				if(sum >= 1000000){
					cout << v[i].first << endl;
					num++;
				}
			}
		}

		if(num == 0){
			cout << "NA" << endl;
		}

		cin >> n;
	}

	return 0;
}

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

int main(void){
	int a,b,c;
	int n;
	while(cin>>n,n){
		lli m[4001];
		bool f=false;
		for(int i=0;i<=4000;i++)m[i]=0;
		while(n--){
			cin>>a>>b>>c;
			m[a]+=b*c;
			if(m[a]>=1000000)f=true;
		}
		if(f){
			for(int i=0;i<=4000;i++){
				if(m[i]>=1000000)cout<<i<<endl;
			}
		}else{
			cout<<"NA"<<endl;
		}
	}
	return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<algorithm>
#include<set>
using namespace std;
typedef long long int ll;

int main()
{
    for(;;){
		ll n,num,pr,co;
		cin >> n;
		if(n==0)return 0;
		ll a[4000];
		for(int i=0;i<4000;i++)a[i]=0;
		for(int i=0;i<n;i++){
			cin >> num >> pr >> co;
			a[num-1]+=pr*co;
		}
		bool f=true;
		for(int i=0;i<4000;i++){
			if(a[i]>=1000000){
				printf("%d\n",i+1);
				f=false;
			}
		}
		if(f)printf("NA\n");
	}
    return 0;
}

C++: #include<iostream>
#include<vector>
int main() {
	std::vector<int> a;
	while (true) {
		int n;
		int c = 0;
		std::cin >> n;
		if (n == 0) {
			break;
		}
		std::vector<int> v(n), w(n);
		int t, u;
		for (int i = 0; i < n; ++i) {
			std::cin >> w[i] >> t >> u;
			v[i] = t*u;
		}
		for (int i = 0; i < n; ++i) {
			for (int l = 0; l < n; ++l) {
				if ((v[i] == v[l]) && (i != l)) {
					v[i] += v[l];
					v.erase(v.begin() + l);
					n -= 1;
				}
			}
		}
		for (int i = 0; i < n; ++i) {
			if (v[i] >= 1000000) {
				a.push_back(w[i]);
				++c;
			}
			if ((c == 0) && (i == n - 1)) {
				a.push_back(0);
			}
		}
		v.clear();
		w.clear();
	}
	for (int i = 0; i < a.size(); ++i) {
		if (a[i] == 0)std::cout << "NA" << std::endl;
		else std::cout << a[i] << std::endl;
	}
	return 0;
}