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>
#include <queue>
#include <stack>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <string>
#include <cmath>
#include <complex>
#include <map>
using namespace std;

#define rep(i,n) for(int i=0;i<int(n);++i)

static const double PI=6*asin(0.5);
typedef complex<double> P;
typedef long long ll;


ll n;

int main(){
	while(cin>>n,n!=0){
		ll id[4005]={0};
		int a[8000]={0};
		
		int cou;
		rep(i,n){
			ll t1,t2,t3;
			cin>>t1>>t2>>t3;
			a[i]=t1;
			//if(id[t1]>0){
				id[t1]+=t2*t3;
			//}
			/*
			else{
				id[t1]=t2*t3;
			}
			*/
			cou=i;
		}
		bool f=true;
		rep(i,cou){
			if(id[a[i]]>=1000000){
				cout<<a[i]<<endl;
				id[a[i]]=0;
				f=false;
			}
		}
		if(f) cout<<"NA"<<endl;
	}
	return 0;
}

C++: #include <vector>
#include <string>
#include <utility>
#include <iostream>
#include <algorithm>
using namespace std;
using worker_t = pair<string,int>;

int main() {
	while (true) {
		int n; // number of workers
		cin >> n;
		if (n == 0) {
			break;
		}
		vector<worker_t> v;
		while (n--) {
			string i;
			int q,p;
			cin >> i >> q >> p;
			auto w_itr = find_if(v.begin(),v.end(),[i](worker_t w) { return w.first == i; });
			if (w_itr == v.end()) { // if the worker not exist
				v.push_back({i,q*p});
			} else {
				w_itr->second += q*p;
			}
		}
		int count = 0;
		for (auto itr = v.begin();itr != v.end();++itr) {
			if (itr->second >= 1000000) {
				cout << itr->first << endl;
				++count;
			}
		}
		if (count == 0) {
			cout << "NA" << endl;
		}
	}
}

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

using namespace std;

struct data{
  int id;
  int  price;
  int  amount;
  long long rate;
};

int main(){
  int n=0;
  while(1){
    cin>>n;
    if(n==0){return 0;}
    vector<struct data> data(n);
    int c=0;
    for(int i=0;i<n;i++){
      scanf("%d %d %d",&data[i].id,&data[i].price,&data[i].amount);
      data[i].rate=data[i].price*data[i].amount;
    }
    vector<struct data> res(n);
    for(int i=0;i<n;i++){
      res[i].id=0;
      res[i].rate=0;
    }
    for(int i=0;i<n;i++){
      int find=0;
      for(int j=0;j<i;j++){
	if(data[i].id==res[j].id){
	  res[j].rate+=data[i].rate;
	  find=1;
	  break;
	}
      }
      if(find==0){
	res[i].id=data[i].id;
	res[i].rate=data[i].rate;
      }
    }
    for(int i=0;i<n;i++){
      if(res[i].id!=0&&res[i].rate>=1000000){
	cout<<data[i].id<<"\n";
	c++;
      }
    }
    if(c==0){
      cout<<"NA\n";
    }
  }
  return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
void shoki();
	vector<long long> num(3999,0);
	int n,ban,tanka,kazu,i,j;
int main(){
	bool y=false;
	for(j=0;j<50;j++){
		cin>>n;
		if(n==0){
			break;
		}
		int count=0;
		for(i=0;i<n;i++){
			cin>>ban>>tanka>>kazu;
			num[ban]+=tanka*kazu;
		}
		for(int k=0;k<3999;k++){
			if(num[k]==0){
				continue;
			}
			if(num[k]>=1000000){
				y=true;
				cout<<k<<endl;
			}
		}
		if(y==false){
			cout<<"NA"<<endl;
		}
		y=false;
		shoki();
	}
	return 0;
}
void shoki(){
	for(int i=0;i<3999;i++){
		num[i]=0;
	}
}

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

int main()
{
	long long n,a,b,c;
	while(cin >> n, n)
	{
		vector<long long>  v;
		map<long long,long long> m;

		while(n--)
		{
			cin >> a >> b >> c;
			if(m.insert(pair<long long,long long>(a,b*c)).second)
			{
				v.push_back(a);
			}
			else
			{
				m[a] += b*c;
			}
		}

		bool f=true;
		for(int i=0; i<v.size(); i++)
		{
			if(m[v[i]]>=1000000)
			{
				f=false;
				cout << v[i] << " " << m[v[i]] << endl;
			}
		}
		if(f) cout << "NA" << endl;
	}
	return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<algorithm>
#include<climits>
#include<string>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<cstring>
using namespace std;

int A[1000000];

signed main(){
	int N,B,C;
	while(cin>>N,N){
		int cnt[4001]={};
		bool NAflag=true,used[4001]={};
		for(int i=0;i<N;i++){
			cin>>A[i]>>B>>C;
			cnt[A[i]] += B*C;
		}
		for(int i=0;i<N;i++){
			if(cnt[A[i]]>=1000000 && used[A[i]]==false){
				printf("%d\n",A[i]); used[A[i]] = true; NAflag = false;
			}
		}
		if(NAflag==true) puts("NA");
	}
    return 0;
}

C++: #include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
long long int st[4444];
int stf[4444];
int main(void)
{
  while(1){
    int n;
    bool f = true;
    cin >> n;
    if(!n) break;
    memset(st,0,sizeof(st));
    memset(stf,0,sizeof(stf));
    for(int i = 0; i < n; i++){
      long long int a,b,c;
      cin >> a >> b >> c;
      st[a] += b * c;
      if(1000000 <= st[a] && !stf[a]){
	cout << a << endl;
	stf[a] = 1;
	f = false;
      }
    }
    if(f) puts("NA");
  }
}

C++: #include <iostream>
using namespace std;
typedef long long ll;
//vector<pair<bool, ll>> v(4001);
ll a[4001];

int main(){
	int n, num, p, q;
	while(cin >> n, n){
		fill(a, a+4001, 0);
		int f = 1;
		//for(int i = 0;i < 4001;i++)a[i] = 0;
		for(int i = 0;i < n;i++){
			cin >> num >> p >> q;
			a[num] += p * q;
			if(a[num]>999999){
                cout << num << endl;
                f = 0;
            }
		}
		if(f)cout << "NA" <<endl;
		/*int f = 1;
		for(int i = 1;i <= 4000;i++)if(a[i] >= 1000000)cout << i << endl, f = 0;
		if(f)cout << "NA" << endl;*/
	}
	return 0;
}

/*
4
1001 2000 520
1002 1800 450
1003 1600 625
1001 200 1220
*/

C++: #include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
using namespace std;
typedef long long int ll;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}


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

        ll a[4001]  = {};

        int retu[4000];
        int count = 0;
        int flag[4001] = {};

        rep(i,n){
            int e;
            ll p,q;
            cin >> e >> p >> q;
            a[e] += p*q;
            //cout << a[e];
            if(flag[e]==0){
                retu[count] = e;
                count++;
                flag[e] = 1;
            }
        }
        int f = 0;
        rep(i,count){
            //cout << a[retu[i]];
            if(a[retu[i]]>=1000000){
                cout << retu[i] << endl;
                f = 1;
            }
        }
        if(f==0){
            cout << "NA" << endl;
        }

    }
    return 0;
}

C++: #include<iostream>
#include<cstring>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdio>
#include<cmath>
#define pb(in,tmp) in.push_back(tmp)
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,b) loop(i,0,b)
#define all(in) in.begin(),in.end()
using namespace std;
int main(){
int n;
while(cin>>n,n){
long long int tmp[4001]={0};
vector<int>no;
rep(i,n){
int a,b,c;
cin>>a>>b>>c;
pb(no,a);
tmp[a]+=b*c;
}
int co=0;
rep(i,n){
if(tmp[no[i]]>=1000000){
int han=0;
rep(j,i){
if(no[i]==no[j]){
han=1;
break;
}
}
if(han)continue;
co++;
cout<<no[i]<<endl;
}
}
if(!co)cout<<"NA"<<endl;
}
}