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 <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <sstream>
#include <vector>
#include <string>
#include <iomanip>
#include <bitset>
using namespace std;
#define INF	100000000
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define fi first
#define sec second
#define lb lower_bound
#define ub upper_bound
#define SS stringstream
#define rep(i,n) for(int i = 0; i < n; i++)
#define sz(x) ((int)(x).size())
#define SORT(x) sort((x).begin(), (x).end())
#define RSORT(x) sort((x).begin(), (x).end(), greater<int>() )
#define clr(a,b) memset((a),(b),sizeof(a))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<int> Vi;
typedef vector<ll> Vll;
typedef vector<P> Vp;
typedef priority_queue<P, vector<P>, greater<P> > PQ;

int n;
map<int,ll>::iterator it;

int main(){
	while(scanf("%d", &n)){
		if(n == 0) break;
		map<int,ll> m;
		rep(i,n){
			int x; ll p,q; scanf("%d%lld%lld", &x, &p, &q);
			if(m.find(x) == m.end()) m[x] = p*q;
			else m[x] += p*q;
		}
		bool ok = true;
		for(it = m.begin(); it != m.end(); it++){
		//	cout << it->first << " " << it->second << endl;
			if(it->second >= 1000000){
				ok = false;
				cout << it->first << endl;
			}
		}
		if(ok) cout << "NA" << endl;
	}
}

C++: //include
//------------------------------------------
#include <iostream>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
using namespace std;

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORR(i,a,b) for(int i=(a);i>(b);i--)
#define REP(i,n)  FOR(i,0,n)

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//debug
//-------------------------------------------
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

long long data[4001];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n;
    while(1) {
        cin >> n;
        if (!n) break;
        memset(data, 0, sizeof(data));
        REP(i, n) {
            int e;
            long long p, q;
            cin  >> e >> p >> q;
            data[e] += p * q;
        }
        int c = 0;
        FOR(i, 1, 4001) {
            if (data[i] >= 1000000) {
                cout << i << endl;
                ++c;
            }
        }
        if (!c) cout << "NA" << endl;
    }
    return 0;
}

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

int main(){
	int n, s, m, No;
	bool flag;
	bool person[6000];
	
	while( cin >> n, n){
		flag = true;
		for(int i=0 ; i<6000 ; i++)
			person[i] = false;
		
		for(int i=0 ; i<n ; i++){
			cin >> No >> s >> m;
			if( s*m >= 1000000){
				flag = false;
				person[No] = true;
			}
		}
		if(flag){
			cout << "NA" << endl;
		}else{
			for(int i=0 ; i<6000 ; i++)
				if(person[i])
					cout << i << endl;
		}
	}
	
	return 0;
}

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

#define loop(i,a,b) for(int i=(a); i<(int)(b); i++)
#define rep(i,b) loop(i,0,b)
#define all(c) (c).begin(), (c).end()
 
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

int main() {
  int n;
  while(cin >> n, n) {
    int a[4100] = {};
    vi in(n);
    rep(i, n) {
      int p, q, r; cin >> p >> q >> r;
      a[p] += q*r;
      in[i] = p;
    }

    bool b = false;
    rep(i, n) {
      if(a[in[i]] >= 1000000) {
        cout << in[i] << endl;
        a[in[i]] = 0;
        b = true;
      }
    }
    if(!b) cout << "NA" << endl;
  }
}

C++: #include<iostream>
#include <fstream>
#include <stdio.h>
#include <stdlib.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include<string>
#include<vector>
#include<cmath>
#include<stack>
#include<queue>
#include<sstream>
#include<algorithm>
#include<map>
#include<complex>
using namespace std;


#define li			long long int
#define rep(i,to)	for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)	for(li i=(li)(start);i<((li)(to));i++)
#define pb			push_back
#define sz(v)		((li)(v).size())
#define bgn(v)		((v).begin())
#define eend(v)		((v).end())
#define allof(v)	(v).begin(), (v).end()
#define dodp(v,n)		memset(v,(li)n,sizeof(v))
#define bit(n)		(1ll<<(li)(n))
#define mp(a,b)		make_pair(a,b)
#define rin	rep(i,n)
#define EPS 1e-10
#define ETOL 1e-8
#define MOD 1000000007
#define p2(a,b)		cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)		cout<<a<<"\t"<<b<<"\t"<<c<<endl

li shine[4040];
li submit[4040];

int main(){
	li n;
	while(1){
		cin>>n;
		if(n==0)break;
		rep(i,4040)shine[i]=0;
		rep(i,4040)submit[i]=0;
		vector<li> jun;
		rin{
			li a1,a2,a3;
			cin>>a1>>a2>>a3;
			shine[a1]+=a2*a3;
			jun.pb(a1);
		}
		bool ita=false;
		rep(i,sz(jun)){
			if(shine[jun[i]]>=1000000 && submit[jun[i]]==0){
				submit[jun[i]]=1;
				cout<<jun[i]<<endl;
				ita=true;
			}
		}

		if(!ita)puts("NA");
	}

	return 0;
}

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

using namespace std;

int n;
long long id[4000];
unsigned long long value[4000];
unsigned long long number[4000];
map<unsigned long long, unsigned long long> total;

int main() {
  while(true){
    cin >> n;
    if(n==0){
        return 0;
    }
    for (int i = 0; i < n; i++) {
        cin >> id[i] >> value[i] >> number[i];
        if(total.find(id[i])==total.end()){
          total.insert(make_pair(id[i], 0));
        }
        total[id[i]] += value[i] * number[i];
    }
    vector<long long> v;
    if(!total.empty()) {
        map<unsigned long long, unsigned long long>::iterator it = total.begin();
        while (it != total.end()) {
            if ((*it).second >= 1000000) {
                v.push_back((*it).first);
            }
            ++it;
        }
    }
    if (v.empty()) {
        cout << "NA" << endl;
    }
    for (vector<unsigned long long>::iterator it = v.begin(); it != v.end(); ++it) {
        cout << *it << endl;
    }
    v.clear();
    total.clear();
  }
}