Go: package main

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

func main() {
	stdin := bufio.NewScanner(os.Stdin)

	for stdin.Scan() {
		n, _ := strconv.Atoi(stdin.Text())
		if n == 0 {
			break
		}
		sales := make(map[string]int)
		existed := make(map[string]bool)
		order := make([]string, 4000)
		flg := false
		for i := 0; i < n; i++ {
			stdin.Scan()
			l := strings.Split(stdin.Text(), " ")
			e := l[0]
			p, _ := strconv.Atoi(l[1])
			q, _ := strconv.Atoi(l[2])
			sales[e] += p * q
			if !existed[e] {
				order = append(order, e)
				existed[e] = true
			}
		}
		for _, v := range order {
			if sales[v] >= 1000000 {
				fmt.Println(v)
				flg = true
			}
		}
		if flg == false {
			fmt.Println("NA")
		}
	}
}

C++: #include <bits/stdc++.h>
using namespace std ;

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using dict = map<string,int>;
using pii = pair<ll,ll> ;

constexpr int imax = ((1<<30)-1)*2+1 ;
constexpr int inf = 100000000;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0};
const int dx[] = {0,-1,0,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

template<typename T>
void Unique(vector<T> &v){
  sort(all(v));
  v.erase(unique(all(v)),v.end());
}

template<typename T>
T ston(string& str, T n){
  istringstream sin(str) ;
  T num ;
  sin >> num ;
  return num ;
}

void Ans(bool f){
  if(f) cout << "YES"<<endl;
  else cout << "NO"<<endl;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n,a,b,c;
  while(cin >> n && n){
    vector<pair<ll,ll>> v;
    vary(ll,v2,4005,0);
    int cnt=0;
    rep(i,n){
      cin >> a >> b >> c;
      if(v2[a] == 0){
        ++cnt;
        v.push_back(make_pair(cnt,a));
      }
      if(b * c >= 1000000 || v2[a] + b*a >= 1000000){
        v2[a] = 1000000;
      }
      else if(v2[a] <= 1000000)
        v2[a] += b * c;
    }
    sort(all(v),[](const pii &p,const pii &p2){return p.fi < p2.fi;});
    bool f = false;
//     debug(v.size());
    REP(i,0,v.size()){
      if(v2[v[i].se] >= 1000000){
        cout << v[i].se<<endl;
//         debug(v2[v[i].se]);
        f = true;
      }
    }
    if(!f) cout << "NA"<<endl;
  }
  return 0;
}

C++: #include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
typedef complex<double> P;
const int NORMA = 1000000;

int main() {
  int N;
  while(cin >>N && N){
    map<int, int> m;
    REP(i, N){
      int a, b, c; cin >>a >>b >>c;
      m[a] += b * c;
    }
    vector<int> ans;
    for(map<int, int>::iterator it = m.begin(); it != m.end(); ++it) if(it->second >= NORMA) ans.push_back(it->first);
    if(ans.size() == 0) cout <<"NA" <<endl;
    else REP(i, ans.size()) cout <<ans[i] <<endl;
  }
  return 0;
}

C++: #include <cstdio>
#include <cmath>

using namespace std;

int n, e, p, q;

int main() {
  while(scanf("%d", &n), n) {
    for(int i = 0; i < n; i++) {
      scanf("%d %d %d", e, p, q);
      if(p * q >= 1e6) printf("%d\n", e);
    }
  }
}

C++: #include<stdio.h>
#include<math.h>
#include<string.h>


int main(){
	int uriage[4000][2],n,no,tanka,su,i,j,newflag,naflag;
	
	while(0<=scanf("%d",&n)){
		if(n==0) break;
		memset(uriage,0,sizeof(uriage));
		for(i=0;i<n;i++){
			scanf("%d%d%d",&no,&tanka,&su);
			newflag=0;
			for(j=0;j<n;j++){
				if(uriage[j][0]==no){
					uriage[j][1]+=tanka*su;
					newflag=1;
					break;
				}
			}
			if(newflag==0){
				for(j=0;j<n;j++){
					if(uriage[j][0]==0){
						uriage[j][1]+=tanka*su;
						uriage[j][0]=no;
						break;
					}
				}
			}
		}
		naflag=0;
		for(i=0;i<n;i++){
			if(uriage[i][0]==0)break;
			if(uriage[i][1]>=1000000){
				printf("%d\n",uriage[i][0]);
				naflag=1;
			}
		}
		if(naflag==0)printf("NA\n");
	}
	return 0;
}

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

using namespace std;

int main() {

	long long int n, num, p, q, c;
	deque<int> x;

	while(cin >> n) {
		if(n==0)
			break;
		c=0;
		for(int i=0; i<n; i++) {
			int f=1;
			cin >> num >> p >> q;
			if(p*q>=1000000) {
				for(int j=0; j<x.size(); j++) {
					if(x[j]==num)
						f=0;
				}
				if(f) {
					x.push_back(num);
					c++;
				}
			}
		}
		if(c==0)
			cout << "NA" << endl;
		else  {
			for(int i=0; i<c; i++) {
				cout << x[i] << endl;
			}
		}
	}
		
	return 0;

}

C++: #include <bits/stdc++.h>

using namespace std;
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
#define REP(i,n) for(ll i=0;i<n;++i)
#define REPR(i,n) for(ll i=1;i<n;++i)
#define FOR(i,a,b) for(ll i=a;i<b;++i)
  
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()
  
#define MOD (ll)(1e9+7)
#define ADD(a,b) a=((a)+(b))%MOD
#define FIX(a) ((a)%MOD+MOD)%MOD

typedef long double Real;
#define EPS 1e-13
#define EQ(x) (-EPS<x && x<EPS)
typedef complex<Real> P;
Real dot(P a,P b){return real(conj(a)*b);}
Real cross(P a,P b){return imag(conj(a)*b);}

#define MP make_pair<int,int>

ll score[4001];

int main(){
  while(true){
    int n;
    cin>>n;
    if(!n)break;
    REP(i,4001)score[i]=0;
    REP(i,n){
      int id;
      ll val,num;
      cin>>id>>val>>num;
      score[id] += val*num;
      score[i] = min(score[i], 1000000ll);
    }
    bool flag = true;
    REP(i,4001){
      if(score[i]>=1000000ll){
        flag = false;
        cout<<i<<endl;
      }
    }
    if(flag)cout<<"NA"<<endl;
  }
  return 0;
}

C++: #include<stdio.h>
#define max 1000000

long long int id[4000],raw[4000];

int main(){
    long long int num,sale,d;
    int n,i,j,count,k,l,m;

    for(;;){
    
        scanf("%lld",&n);

        for (k=0;k<=4000;k++){
        
            id[k] = 0;
        }

        if(n==0)break;

        else{
            count = 0;
            for(i=1;i<=n;i++){
                scanf("%lld %lld %lld",&num,&sale,&d);
                id[num] += (sale * d);
                raw[i] = num;
            }
            for(l=0;l<4000;l++){
                for(m=l+1;m<=4000;m++){
                    if(raw[l]==raw[m])raw[m]=0;
                }
            }
            for(j=1;j < 4000;j++){
                if(id[raw[j]] >=  max){
                    printf("%lld\n",raw[j]);
                    count++;
                }
            }
        if(count==0)printf("NA\n");
        

        }
    }
  return 0;
}