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 <cstdio>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, ll> P;
 
int n;
 
int main(){
	while(scanf("%d", &n),n){
		vector<P> vec;
		for(int i = 0; i < n; i++){
			int x; ll p, q;
			scanf("%d%lld%lld", &x, &p, &q);
			bool ok = true;
			for(int j = 0; j < vec.size(); j++){
				if(vec[j].first == x){
					vec[j].second += p*q;
					ok = false;
					break;
				}
			}
			if(ok) vec.push_back(P(x,p*q));
		}
		bool ok = true;
		for(int i = 0; i < vec.size(); i++){
			if(vec[i].second >= 1000000){
				ok = false;
				printf("%d\n", vec[i].first);
			}
		}
		if(ok) printf("NA\n");
	}
	return 0;
}

C++: #include<iostream>

using namespace std;

int main(void){
	int n;
	int a,b,c,d;
	int num[4001],tan[4001],ans[4001];
	bool flag=false;
	while(1){
		for(a=0;a<=4000;a++){
			num[a]=0;
			tan[a]=0;
			ans[a]=0;
		}
		flag=false;
		cin >> n;
		if(n==0)break;
		for(a=0;a<n;a++){
			cin >> b >> c >> d;
			num[b]+=c,tan[b]+=d;
		}
		for(a=1;a<=4000;a++){
			if(num[a]*tan[a]>=1000000)printf("%d\n",a),flag=true;
		}
		if(flag==false)printf("NA\n");
	}
	return 0;
}

C++: #include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <complex>
using namespace std;

typedef long long ll;
typedef pair<int,int> P;

#define all(c) (c).begin(),(c).end()
#define pb push_back
#define mp make_pair
#define ERASE(v,i) (v).erase(remove(all(v),i),(v).end())
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define each(it,c) for(typeof((c).begin()) it=(c).begin();it!=(c).end();++it)
#define debug(x) cerr<<#x<<" = "<<(x)<<endl;
#define LINE cerr<<"LINE: "<<__LINE__<<endl;

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();}
template<class T> void preview(T a,T b){for(T it=a;it!=b;++it)cerr<<*it<<" ";cerr<<endl;}

const int INF = 100000000;
const double PI = acos(-1.0), EPS = 1e-10;

int main() {
	for(int N; cin >> N, N;) {
		vector<ll> shine(4001, 0LL);
		queue<int> idx;
		rep(i,N) {
			int num;
			ll a, b;
			cin >> num >> a >> b;
			if(shine[num] == 0) {
				shine[num] = a * b;
				idx.push(num);
			} else {
				shine[num] += a * b;
			}
		}
		bool f = false;
		while(!idx.empty()) {
			int t = idx.front(); idx.pop();
			if(shine[t] >= 1000000LL) {
				cout << t << endl;
				f = true;
			}
		}
		if(!f) cout << "NA" << endl;
	}
	return 0;
}

C++: #include<stdio.h>

int main(void)
{
	struct employee
	{
		int N,P,A;
	};
	employee person[4000];
	int a,b=0,c;
	for(;;b=0)
	{
		scanf("%d",&c);
		if(c==0)
			break;
		for(a=0;a<c;a++)
			scanf("%d %d %d",&person[a].N,&person[a].P,&person[a].A);
		for(a=0;a<c;a++)
		{
			if(person[a].P*person[a].A>=1000000 )
			{
				printf("%d\n",person[a].N);
				b++;
			}
		}
		if(b==0)
			printf("NA\n");
	}
}

C++: #include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <stdio.h>

using namespace std;

typedef long long ll;

int n, id, p, q;
ll amount;

const ll MAX = 1000000;

struct Mem {
    int id;
    ll c;

    Mem() {}
    Mem(int _id, ll _c) { id = _id; _c = c; }
};

Mem array[4010];
vector<int> ans;

int main(void) {
    while(~scanf("%d", &n)) {
        if(n == 0) break; ans.clear();
        for(int i = 0; i < n; i++) {
            array[i].c = array[i].id = 0;
            scanf("%d%d%d", &id, &p, &q);
            array[i].c += p * q;
            array[i].id = id;
        }
        for(int i = 0; i < n; i++) {
            ll cost = 0;
            for(int j = 0; j < n; j++) {
                if(array[i].id == array[j].id) {
                    cost += array[j].c;
                }
            }
            if(cost >= MAX && !count(ans.begin(), ans.end(), array[i].id)) {
                ans.push_back(array[i].id);
            }
        }
        if(ans.empty()) {
            printf("NA\n");
        } else {
            for(int i = 0; i < (int) ans.size(); i++) {
                printf("%d\n", ans[i]);
            }
        }
    }
    return 0;
}

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

struct staff {
	unsigned long long int num;
	unsigned long long int price;
	unsigned long long int quan;
	unsigned long long int total;
};

int main()
{
	int num, i, k, j, datas;
	int sn, sp, sq;
	map<int, staff> staffs[4000];
	map<int, staff>::iterator staffs_it;

	datas = 0;
	while(1)
	{
		cin >> num; if(num == 0) break;

		for(i = 0; i < num; i++)
		{
			cin >> sn >> sp >> sq;
			staffs[datas][sn].num = sn;
			staffs[datas][sn].price = sp;
			staffs[datas][sn].quan = sq;
			staffs[datas][sn].total += staffs[datas][sn].price * staffs[datas][sn].quan;
		}
		datas++;
	}

	for(i = 0; i < datas; i++)
	{
		staffs_it = staffs[i].begin();
		int over = 0;

		while(staffs_it != staffs[i].end())
		{
			if(staffs[i][(*staffs_it).first].total >= 1000000)
			{
				cout << staffs[i][(*staffs_it).first].num << endl;
				over++;
			}
			staffs_it++;
		}
		if(over == 0) cout << "NA" << endl;
	}
}

C++: #include <cstdio>
#include <map>
#include <algorithm>
using namespace std;
pair<int, long long int> s[4001];

int main() {

    int n, id, p, q, idx;
    for (;;) {
        scanf("%d", &n);
        if (n == 0) break;
        for (int i = 0; i < n; i++) { s[i] = {0, 0}; }
        map<int, int> m;
        idx = 0;
        for (int i = 0; i < n; i++) {
            scanf("%d %d %d", &id, &p, &q);
            if (m.find(id) == m.end()) {
                m.insert({id, idx});
                s[idx++] = {id, p*q};
            }
            else {
                s[m[id]].second += p*q;
            }
        }
        bool flag = false;
        for (int i = 0; i < m.size(); i++) {
            if (s[i].second >= 1000000) { flag = true; printf("%d\n", s[i].first); }
        }
        if (!flag) printf("NA\n");
    }

    return 0;
}

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

const int BORDER = 1000000;

class myMap
{
public:
	myMap() :mSize( 0 ){}

	void insert( int id, int p, int q ){
		bool find = false;
		long long gross = ( long long )p * q;
		for( int i = 0; i < mSize; ++i ){
			if( mIDList[ i ].first == id ){
				if( mIDList[ i ].second < 1000000 ){
					mIDList[ i ].second += gross;
				}
				find = true;
				break;
			}
		}
		if( !find ){
			mIDList.push_back( pair< int, long long >( id, gross ) );
			++mSize;
		}
	}
	void output(){
		bool finded = false;
		for( int i = 0; i < mSize; ++i ){
			if( mIDList[ i ].second >= BORDER ){
				finded = true;
				cout << mIDList[ i ].first << endl;
			}
		}
		if( !finded ){
			cout << "NA" << endl;
		}
	}

	vector< pair< int, long long > > mIDList;
	int mSize;
};

int main()
{
	int n;

	while( cin >> n && n ){
		myMap db;
		int id, unit, amount;
		for( int i = 0; i < n; ++i ){
			cin >> id >> unit >> amount;
			db.insert( id, unit, amount );
		}
		db.output();
	}

	return 0;
}