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;
int ans[4000];

int main(){
	int N;
	int n,e;
	long long int p, q;
	int x;
	while (1){
		x = 0;
		cin >> N;
		n = N;
		if (N == 0){ break; }
		while (N){
			cin >> e >> p >> q;
			if (p*q >= 1000000){
				ans[x] = e;
				x++;
			}
			N--;
		}
		if (ans[0] == 0){ cout << "NA" << endl; }
			for (int i = 0; i < n; i++)
			{

				if (ans[i] == 0){ break; }
				cout << ans[i] << endl;
			}
	}
	return 0;
}

C++: #include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<utility>
#include<set>
#include<complex>
#include<map>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<double,double>pdd;
typedef pair<ll,ll>pll;
#define int ll
signed  main(){
    int n;
    while(cin>>n,n){
        map<int,int>mp;
        rep(j,n){
            int a,b,c; cin>>a>>b>>c;
            mp[a]+=b*c;
        }
        bool flag=false;
        for(auto itr=mp.begin();itr!=mp.end();itr++)
            if(mp[itr->first]>=1000000){flag=true;cout<<itr->first<<endl;}
        if(!flag)cout<<"NA"<<endl;
    }
}

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

using namespace std;

int main(void){
    int i,j,k,l;
    int n;
    int id,cost,qty;
    int data_list[4001];
    int id_list[4000];
    bool id_flag;
    bool na_flag;
    
    while(cin>>n,n!=0){
        fill(data_list,data_list+4000,0);
        k=0;
        for(l=0;l<n;l++){
            data_list[id]+=(cost*qty);
            cin>>id>>cost>>qty;
            id_flag=true;
            for(i=0;i<=k+1;i++){
                if(id_list[i]==id){
                    id_flag=false;
                }
            }
            if(id_flag){
                id_list[k]=id;
                k++;
            }
        }
        na_flag=true;
        for(l=0;l<k;l++){
            if(data_list[id_list[l]]>=1000000){
                cout<<id_list[l]<<endl;
                na_flag=false;
            }
        }
        if(na_flag){
            cout<<"NA"<<endl;
        }
    }
    return(0);
}

C++: #include<iostream>
#include<map>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
    int n,a,b,c;
    while(cin>>n,n){

        vector<int>V;
        map<int,long long>M;
        while(n--){
            cin>>a>>b>>c;
            if(M[a]==0)V.push_back(a);
            M[a]+=b*c;

        }

        int cnt=0;
        sort(V.begin(),V.end());
        for(int i=0;i<V.size();i++){
            if(M[V[i]]>=1000000){
                cnt++;
                cout<<V[i]<<endl;
            }
        }
        if(cnt==0)cout<<"NA"<<endl;
    }
    return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
  int n;
  int t[5000]={0};
  long long sum[5000]={0};
  bool NA=true;
  while(cin>>n,n){
    NA=true;
    for(int i=0;i<5000;i++){
      t[i]=0; sum[i]=0;
    }
    int a,b,c;
    for(int i=0;i<n;i++){
      cin>>a>>b>>c;
      for(int j=0;j<5000;j++){
	if(t[j]==a)break;
	if(t[j]==0){t[j]=a;break;}
      }
      
      if(sum[a]<=1000000)sum[a]+=b*c;
    }
    for(int i=0;i<5000;i++){
      if(sum[t[i]]>=1000000){
	cout<<t[i]<<endl; NA=false;
      }
    }
    if(NA)cout<<"NA"<<endl;
  }
}

C++: #include <iostream>

using namespace std;

//empoyer,price,quantity;
int main()
{
    
    while (1){
        int num;
        cin >> num;
        if (num == 0) break;
        int employer[4001][2] = {0};
        
        int e, p, q;
        int ans[4001] = {0};
        for (int i = 0; i < num; i++) {
            cin >> e >> p >> q;
            ans[i] = e;
            employer[e][0] = employer[e][0] + (p * q);
            if (employer[e][0] >= 1000000) {
                employer[e][1] = 1;
            }
        }
        bool answer = true;
        for (int i = 0; i < num; i++ ) {
            if (employer[ans[i]][1] == 1) {
                cout << ans[i] << endl;
                employer[ans[i]][1] = -1;
                answer = false;
            }
        }
        if (answer) cout << "NA" << endl;
    }
    return 0;
}

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){
		map <ll,ll> id;
		vector<ll> a;
		rep(i,n){
			ll t1,t2,t3;
			a.push_back(t1);
			cin>>t1>>t2>>t3;
			//if(id[t1]>0){
				id[t1]+=t2*t3;
			//}
			/*
			else{
				id[t1]=t2*t3;
			}
			*/
		}
		bool f=true;
		rep(i,a.size()){
			if(id[a[i]]>=1000000){
				cout<<a[i]<<endl;
				id[a[i]]=0;
				f=false;
			}
		}
		if(f) cout<<"NA"<<endl;
	}
	return 0;
}

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

int main(){
 int id,price,num,count;
 int sameid[4000];
 bool isBe=false,isSame=false;

 while(true){
  cin>>count;
  if(count==0){
   break;
  }
  for(int i=0;i<count;i++){
   cin>>id>>price>>num;
   for(int j=0;j<=i;j++){
    if(id==sameid[j]){
      isSame=true;
      break;
    }
   }
   sameid[i]=id;
   if(price*num>=1000000&&!isSame){
    cout<<id<<'\n';
    isBe=true;
   }
   isSame=false;
  }
  if(!isBe){
   cout<<"NA\n";
  }
  count=0;
  isBe=false;
  for(int i=0;i<count;i++){
   sameid[i]=0;
  }
 }
 return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;

int main() {
  int n;
  while(cin >> n, n) {
    int f=0;
    REP(i,n) {
      ll a,b,c;
      cin >> a>>b>>c;
      if (b*c>=1000000) {
        if (f==0)
          f=1;
        cout << a << endl;
      }
    }
    if (f==0)
      cout << "NA" << endl;
  }
}