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;
  
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;
    bool flag = true;
    REP(i,n){
      int id;
      ll val,num;
      cin>>id>>val>>num;
      score[id] += val*num;
      if(score[id]>=1000000ll){
        flag = false;
        cout<<id<<endl;
        score[id] = -1145141919810931;
      }
    }
    if(flag)cout<<"NA"<<endl;
  }
  return 0;
}

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




int n;


void solve()
{
	bool ok=false;
	for(int i=0;i<n;i++){
		int num,a,b;
		cin>>num>>a>>b;
		if(a*b>=1000000){
			cout<<num<<endl;
			ok=true;
		}
	}
	if(!ok) cout<<"NA"<<endl;
}

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

C++: #include <iostream>
using namespace std;
int main ()
{

    int n=1,num,tanka,suryo;
    long long sum[4001]={0};
    bool na=true;
    while(true){
        cin>>n;
        if(n==0){
            return 0;
        }
        for(int i=0;i<n;i++){//ツ禿シツ療債つウツづェツつスツ値ツづーツ各ツ配ツ療ア(ツ偲青暗オツ氾板債づ可格ツ納)
            cin>>num>>tanka>>suryo;
            sum[num]+=tanka*suryo;
        }
        for(int i=1;i<=4000;i++){
            if(sum[i]!=0)cout<<sum[i]<<endl;
            if(sum[i]>=1000000){cout<<i<<endl;na=false;}
            sum[i]=0;//ツ篠淞づ可使ツつ、ツづヲツつ、ツづ可渉可甘コツ可サツづーツつオツづつィツつュ
        }
        if(na)cout<<"NA"<<endl;
        na=true;
    }
}

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

int main(){

	int N,Q;
	while(1){int c=0;
	cin>>N;if(N==0)break;
	long long int n[4002][2]={};
	for(int i=0;i<4001;i++)
		n[i][1]=0;

	for(int i=0;i<N;i++){
		long long int x,y,z;
		cin>>x>>y>>z;
		if(n[x][0]+y*z<=1000000)n[x][0]+=y*z;
		else if(n[x][0]+y*z>1000000)n[x][0]=1000000;
		if(n[x][1]==0){c++;n[x][1]=c;}
	
	}
	for(int i=0;i<4001;i++){
		for(int j=i;j>i;j--){
			if(n[j][1]<n[j-1][1]){
				int t=n[j][0];n[j-1][0];n[j-1][0]=t;
				int T=n[j][1];n[j-1][1];n[j-1][1]=T;
			}
		}
	}
	bool f=false;
	for(int i=0;i<4001;i++){
		if(n[i][0]>=1000000){cout<<i<<endl;f=true;}
	}
	if(f==false)cout<<"NA"<<endl;

	}
	return 0;
}

C++: #include <cstdio>
#include <cstdlib>
#include <cmath>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <cstring>
#include <functional>

using namespace std;

#define REP(i,a,b) for((i)=(a);(i)<(int)(b);(i)++)
#define rep(i,n) REP(i,0,n)
#define foreach(itr,c) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
#define ll long long

ll data[4010];
bool out[4010];

int main(){
  int i,j,k,n;
  ll a, b;
  int id;

  while(scanf("%d",&n)){
    if(n == 0) break;
    vector<int> ids;
    bool f = false;

    rep(i,4010) data[i] = 0;
    rep(i,4010) out[i] = false;

    while(n--){
      scanf("%d %lld %lld",&id,&a,&b);

      ids.push_back(id);
      data[id] += a * b;
      if(data[id] >= 1000000LL) out[id] = true;
    }

    rep(i,ids.size()) if(out[ids[i]]){
      printf("%d\n",ids[i]);
      out[ids[i]] = false;
      f = true;
    }

    if(f) puts("NA");
  }

  return 0;
}

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

int main() {
    int i[4000], p, q, sum[4000];
    for (; ; ) {
        int n, count;
        cin>>n;
        if (n) {
            count = 0;
            for (int j = 0; j < n; j++) {
                cin>>i[j]>>p>>q;
                sum[j] = p * q;
                if (j == 0 && sum[j] >= 1000000) {
                    cout<<i[j]<<endl;
                    count++;
                }
                for (int k = 0 ; k < j; k++) {
                    if (i[k] == i[j]) {
                        if (sum[k] >= 1000000) {
                            break;
                        } else {
                            sum[k] += sum[j];
                            if (sum[k] >= 1000000) {
                                cout<<i[j]<<endl;
                                count++;
                            }
                            break;
                        }
                    }
                }
            }
            if (count == 0) {
                cout<<"NA"<<endl;
            }
        } else
            break;
    }
    return 0;
}

C++: #include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
typedef pair<int,int>pii;
int main(){
    int n;
    while(cin>>n,n){
        long long S[4000]={0};
        int B[4000]={0},cnt=1;
        while(n--){
            int n,m,o;
            cin>>n>>m>>o;
            S[n-1]+=m*o;
            if(B[n-1]==0){
                B[n-1]=cnt;
                cnt++;
            }

        }
        vector<pii>V;
        for(int i=0;i<4000;i++)
            if(S[i]>=1000000){
                V.push_back(pii(B[i],i));
            }
        sort(V.begin(),V.end());
        for(int i=0;i<V.size();i++)cout<<V[i].second+1<<endl;
        if(V.size()==0)cout<<"NA"<<endl;
    }
}

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

using namespace std;

typedef unsigned long long ll;

ll data[4001];
vector<int> V;

void print(){
  vector<int> M;
  for(int i = 0; i < 4001; i++)
    if(data[i] >= 1000000) M.push_back(i);
  if(M.size()){
    for(int i = 0; i < V.size(); i++)
      if(binary_search(M.begin(),M.end(),V[i])) cout << V[i] << endl;
  }else cout << "NA" << endl;
}
int main(){
  ll in;
  while(cin >> in && in){
    V.clear();
    fill(data,data+4001,0);
    for(int i = 0; i < in; i++){
      ll num,p,q;
      cin >> num >> p >> q;
      if(!binary_search(V.begin(),V.end(),num)) V.push_back(num);
      if(data[num] < 1000000)data[num] += p*q;
    }
    print();
  }
  return 0;
}