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++: // #define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <locale>
#include <cctype>
#include <sstream>	// istringstream
using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<VI> VVI;

#define MP make_pair
#define fastIO	cin.tie(0); ios::sync_with_stdio(false);
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
//for gcc (未test)
// #define FOREACH_IT(it,c)	for(typeof(c)::iterator it=(c).begin(); it!=(c).end(); ++it)
//for Visual Studio
#define foreach_it(type,it,c) for(type::iterator it=c.begin(); it!=c.end(); ++it)

// #defineの初利用にあたって参考にした http://peroon.hatenablog.com/entry/20091123/1258966199
// iteratorのforLoop                   http://bokko.hatenablog.com/entry/20090320/1237494217
// fastIO                              https://gist.github.com/rigibun/7905920

void solveAndOutput(map<int, long long> data, VI bangouList){
	int outputCount = 0;

	FOR(i, 0, bangouList.size()){
		if (data[bangouList[i]] >= 1000000){
			cout << bangouList[i] << endl;
			outputCount++;
		}
	}
	if (outputCount == 0)
		cout << "NA" << endl;
}

int main(){
	// sankou http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=97994#1

	long long n;
	// 重複なし、自動ソート
	map<int, long long> data;
	// 重複あり、ソートなし -> 重複するものは格納しないようにしたい.
	VI bangouList;
	//fastIO;

	while (cin >> n, n){
		data.clear();
		bangouList.clear();
		while (n--){
			int bangou = 0, tanka = 0, suu = 0;
			cin >> bangou >> tanka >> suu;
			if(!data[bangou])
				bangouList.push_back(bangou);
			data[bangou] += tanka * suu;
		}
		solveAndOutput(data, bangouList);
	}
	return 0;
}

C++: #include<iostream>
#include<string.h>
#include<vector>
#include<list>
#include<stdio.h>
#include<math.h>
#include<iomanip>
#include<map>
#include<stack>
#include<queue>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define debug(x) cout << "debug " << x << endl;
using namespace std;

int main(){
    int n;
    while(cin >> n, n){
        map<int, long long> info;
        map<int, long long>::iterator it;
        rep(i,n){
            int a, b, c;
            cin >> a >> b >> c;
            info[a] += b * c;
        }
        bool c = true;
        for(it = info.begin(); it != info.end(); it++){
            if(it->second >= 1000000){
                cout << it->first << endl;
                c = false;
            }
        }
        if(c) cout << "NA" << endl;
    }
}

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

int main() {
	int i, n, no[4000], tanka[4000], num[4000];
	bool flg=false;
	while (1) {
		flg=false;
		cin>>n;
		if (n==0) break;
		for (i=0; i<n; i++)
			cin>>no[i]>>tanka[i]>>num[i];
		for (i=0; i<n; i++) {
			if (tanka[i]*num[i]>=1000000)
				flg=true, cout<<no[i]<<endl;
		}
		if (flg==false) cout<<"NA"<<endl;
	}
	return 0;
}

C++: #include <iostream>

int main()
{
    bool loop = true;

    while (loop) {
        int dataset_num;
        int count = 0;
        std::cin >> dataset_num;

        if (dataset_num == 0) {
            loop = false;
            break;
        }

        for (int i = 0; i < dataset_num; i++) {
            int officer_num;
            int price;
            int figure;
            int officer_num_old;

            officer_num_old = officer_num;
            std::cin >> officer_num;
            std::cin >> price;
            std::cin >> figure;

            if (price * figure >= 1000000 && officer_num != officer_num_old) {
                std::cout << officer_num << std::endl;
                count += 1;
            }
        }
        if (count == 0) {
            std::cout << "NA" << std::endl;
        }
    }

    return 0;
}

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][0]=n[j-1][0];n[j-1][0]=t;
				int T=n[j][1];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 <iostream>
#include <algorithm>
using namespace std;

int main() {
	long long int i, n, no[4000], tanka[4000], num[4000];
	bool flg=false;
	while (1) {
		flg=false;
		cin>>n;
		if (n==0) break;
		for (i=0; i<n; i++)
			cin>>no[i]>>tanka[i]>>num[i];
		for (i=0; i<n; i++) {
			if (tanka[i]*num[i]>1000000)
				flg=true, cout<<no[i]<<endl;
		}
		if (flg==false) cout<<"NA"<<endl;
	}
	return 0;
}

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

using namespace std;

typedef long long ll;

string int_to_str(int n) {
	stringstream ss;
	string ret;

	ss << n;
	ss >> ret;

	return ret;
}


int keta(int n) {
	string str = int_to_str(n);

	return str.size();
}

int main() {
	int n;
	while (cin >> n, n) {
		bool f = false;
		map<int, ll> datas;
		vector<int> noes;
		for (int i = 0; i < n; ++i) {
			int no, a, b; cin >> no >> a >> b;

			if ( find( noes.begin(), noes.end(), no) == noes.end() )
				noes.push_back(no);

			if (datas[no] < 1000000) {
				if (keta(a) + keta(b) - 2 >= 6)
					f = true;

				else if ((datas[no] += a * b) >= 1000000)
					f = true;
			}
		}
		for (int i = 0; i < noes.size(); ++i)
			if (datas[noes[i]] >= 1000000)
				cout << noes[i] << endl;

		if (!f) cout << "NA" << endl;
	}
}

C++: #include <iostream>
using namespace std;
int main()
{
	int n, no[4000], t[4000], num[4000], a[4000], i, j;
	while (cin >> n && n)
	{
		for (i = 0, j = 0; i < n; i++)
		{
			cin >> no[i] >> t[i] >> num[i];
			if (t[i] * num[i] > 1000000)
			{
				a[j] = no[i], j++;
			}
		}
		if (j == 0)
			cout << "NA" << endl;
		else
			for (i = 0; i < j; i++)
				cout << a[i] << endl;
	}
	return 0;
}

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

ll em[4000];
int flag[4000];

int main(){
	int n;
	while(true){
		int id,p,q;
		cin >> n;
		if(!n) return 0;
		for(int i = 0; i < n; i++){
			cin>>id>>p>>q;
			em[id-1] += (ll)p * q;
			flag[i] = id;
		}
		int f = 1;
		for(int i = 0; i < n; i++){
			if(em[flag[i]-1] >= 1000000){
				cout << flag[i] << endl;
				f = 0;
			}
			em[flag[i]-1] = 0;
		}
		if(f) cout << "NA" << endl;
	}
	return 0;
}

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

using namespace std;

int main(void){
	int n;
	while(1){
		cin >> n;
		if(n==0)
			break;
		int c[4001]={} , id[100000];
		for (int i=0; i<n; i++){
			int p , q;
			cin >> id[i] >> p >> q;
			c[id[i]] += p*q;
		}
		for (int i=0; i<n; i++){
			if (c[id[i]]>=1000000){
				cout << id[i] << endl;
				c[id[i]]=0;
			}
		}
	}

	return 0;
}