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<vector>;
using namespace std;
int main() {
	int n;
	while (cin >> n){
		if (n == 0)break;
		long long u[4010] = { 0 };
		vector<int>l;
		for (int i = 0; i < n; i++){
			long a, b, c;
			cin >> a >> b >> c;
			u[a] += b*c;
			if (u[a] >= 1000000 && find(l.begin(), l.end(), a) == l.end())l.push_back(a);
		}
		for (int i = 0; i < l.size(); i++){
			cout << l[i] << endl;
		}
		if (!l.size())cout << "NA" << endl;
	}
	return 0;
}

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

int main(){

  long sale,kosuu,n,bangou;
  while(cin >> n,n){
  int syain[4001] = {0};
    while(n--){
      cin >> bangou >> sale >> kosuu;
      syain[bangou] += kosuu*sale;
    }
    int f = 0;
    for(int i = 1 ; i <= 4000 ; i++  ){
      if(syain[i] >= 1000000){
	cout << i << endl;
	f = 1;
      }
    }
    if(f == 0)cout << "NA" << endl;
  }
}

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

#define REP(i,n) for(int i=0;i<(int)n;++i)

using namespace std;

int main() {
  while(1){
    int n;
    cin>>n;
    if(!n)break;
    vector<int64_t> m(4001);
    vector<int> order;
    set<int> already;
    REP(i,n){
      int64_t no, p, num;
      cin>>no>>p>>num;
      if (!already.count(no)) {
        order.push_back(no);
        already.insert(no);
      }
      m[no] += p * num;
    }
    int cnt = 0;
    for(int no:order) {
      if (m[no] >= 1000000) {
        ++cnt;
        cout << no << endl;
      }
    }
    if (!cnt)
      cout << "NA" << endl;
  }
  return 0;
}

C++: #include<iostream>

using namespace std;

int main(void){
  long long x,emp[4001],val[4001];
  long long emp1,val1,con,flag;

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

    for(int i=0;i<4001;i++){
      emp[i]=0;
      val[i]=0;
    }
    for(int i=0;i<x;i++){
      cin >> emp1 >> val1 >> con;

      flag=0;
      for(int j=0;j<x;j++){
	if(emp[j]==emp1){
	  flag=1;
	  val[j]+=val1*con;
	  break;
	}
      }
      if(flag==0){
	for(int j=0;j<4001;j++){
	  if(emp[j]==0){
	    emp[j]=emp1;
	    val[j]=val1*con;
	    break;
	  }  
	}
      }
    }
      flag=0;
    for(int j=0;j<4001;j++){
      if(val[j]>=1000000){
	cout << emp[j] << endl;
	flag=1;
      }
    }
    if(flag==0)cout << "NA" << endl;
  }
  return 0;
}

C++: #include <iostream>
using namespace std;
int main(){
    long long bangou,tanka,kosuu;
    long long number; cin >> number;
    do{
        long long man[4000];
        for(int i=0;i<4000;i++){
            man[i]=0;
        }
        for(int i=0;i<number;i++){
            cin >> bangou >> tanka >> kosuu;
            man[bangou-1] += tanka*kosuu;
        }
        int count =0;
        for(int i=0;i<4000;i++){
            if(man[i]>=1000000){
                cout << i+1 << endl;
                count++;
            }
        }
        if(count==0)
            cout<< "NA" << endl;
        cin >> number;
    }while(number !=0);

}

C++: #include<cstdio>
#include<algorithm>
#include<iostream>
#include<functional>
#define inf 1000000
using namespace std;
long long int p[114514],x,y,z,w;
int main(void)
{
	int i,j,k,f,n,cnt;
	while(1) {
		cin>>n;
		f=0,cnt=0;
		if(!n)break;
		for(i=0;i<4001;i++) p[i]=0;
		for(i=0;i<n;i++) {
			cin>>x>>y>>z;
			if(p[x]>=inf) continue;
			p[x]+=y*z;
		}
		for(i=0;i<4001;i++) {
			if(p[i]>=inf) {
				cout<<i<<endl;
				f=1;
			}
		}
		if(f==0) cout<<"NA"<<endl;
	}
	return 0;
}

C++: #include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iostream>
#include <cctype>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <bitset>
#include <complex>
#include <fstream>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T> T RoundOff(T a){ return int(a+.5-(a<0)); }
template<class T, class C> void chmax(T& a, C b){ if(a < b) a = b; }
template<class T, class C> void chmin(T& a, C b){ if(b < a) a = b; }
template<class T, class C> pair<T, C> mp(T a, C b){ return make_pair(a, b); }

int main()
{
	int n;
	while(cin >> n && n)
	{
		bool f = true;
		set<int> table;

		rep(i, n)
		{
			ll a, s, num;
			cin >> num >> a >> s;

			if(1000000 <= a * s && table.find(num) == table.end())
			{
				f = false;
				table.insert(num);
				cout << num << endl;
			}
		}

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