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++: /* {{{ Shinobu kawaii */
/*
  ______   __        _                  __                 
.' ____ \ [  |      (_)                [  |                
| (___ \_| | |--.   __   _ .--.   .--.  | |.--.   __   _   
 _.____`.  | .-. | [  | [ `.-. |/ .'`\ \| '/'`\ \[  | | |  
| \____) | | | | |  | |  | | | || \__. ||  \__/ | | \_/ |, 
 \______.'[___]|__][___][___||__]'.__.'[__;.__.'  '.__.'_/ 
                                                           
*/
/* }}} */
/* include {{{ */
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <functional>
using namespace std;
/* }}} */

// #define int long long

/* cpp template {{{ */
/* short */
#define pb push_back
#define mp make_pair
#define print(x) cout << x << '\n'
#define Fi first
#define Se second

/* REPmacro */
#define REPS(i, a, n) for (int i = (a); i < (n); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = 1; i <= (n); i++)
#define DEPS(i, a, n) for (int i = (a); i >= n; i--)
#define DEP(i, n) for (int i = (n); i >= 0; i--)

/* typedef */
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vector<int> > vii;
typedef pair<int, int> pii;

/* const */
const int INF = 999999999;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

/* func */
inline bool is_uruu(int y) {return (y % 4 == 0 && (y % 100 != 0 || y % 400 == 0));}
inline bool inside(int y, int x, int H, int W) {return (y >= 0 && x >= 0 && y < H && x < W);}

/* }}} */

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

  int n;
  while (cin >> n, n){
    ll check[4001] = {0};
    REP(i, n){
      ll num, price, cnt;
      cin >> num >> price >> cnt;
      check[num] += price * cnt;
    }
    bool no = true;
    REP(i, 4001){
      if (check[i] >= 1e6){
        print(i);
        no = false;
      }
    }
    if (no) print("NA");
  }

  return (0);
}

C++: #include <iostream>
using namespace std;
int main()
{
	long long 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>
#include <string>
using namespace std;

int main()
{
	int n,id,sale,k,cnt,flg;
	while (1)
	{
		int outid[4001] = { 0 }, total[4001] = {0};
		cin >> n;
		if (n == 0)break;
		cnt = 0;
		flg = 0;
		for (int i = 0; i < n; i++)
		{
			cin >> id >> sale >> k;
			outid[i] = id;
			total[i] = sale*k;
		}

		for (int i = 0; i < n; i++)
		{
			for (int j = i+1; j < n; j++)
			{
				if (outid[i]==outid[j])
				{
					total[i] += total[j];
					cnt++;
				}
			}
		}

		for (int i = 0; i < n-cnt; i++)
		{
			if (total[i] >= 1000000)
			{
				cout << outid[i] << endl;
				flg = 1;
			}
		}

		if (flg==0)
		{
			cout << "NA" << endl;
		}
		
	}
	return 0;
}

C++: #include<stdio.h>
#include<vector>
typedef long long ll;
int main()
{
	const int N=4001;
	int n,i,p,q;
	while(scanf("%d",&n),n)
	{
		ll e[N]={0};
		std::vector<int>d;
		while(n--)
		{
			scanf("%d%d%d",&i,&p,&q);
			if(!e[i])d.push_back(i);
			e[i]+=(ll)p*q;
		}
		for(i=n=0;i<d.size();++i)if(e[d[i]]>=1000000)n=printf("%d\n",d[i]);
		if(!n)puts("NA");
	}
	return 0;
}

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

int main(){
    int n,i;
    while(cin>>n,n){
        map<int,long long>m;
        vector<int>vec;
        long long p,q,s=0;
        while(n--){
            cin>>i>>p>>q;
            if(!m[i])vec.push_back(i);
            m[i]+=p*q;
        }
//        for (map<int,long long>::iterator it=m.begin(); it!=m.end(); ++it){
//            cout<<it->first<<endl;
//            if(it->second>=1000000){
//                s=1;
//                cout<<it->first<<endl;
//            }
//        }
        for (int i=0;i<vec.size();i++){
            if(m.find(vec[i])->second>=1000000){
                s=1;
                cout<<m.find(vec[i])->first<<endl;
            }
        }
        if(!s)cout<<"NA"<<endl;
    }
}

C++: #include<iostream>

using namespace std;

int main(){
	bool tf = 0;
	int n,e,p,q;
	while(cin >> n){
		if(n == 0){
			break;
		}
		int r[4001]={0};
		tf = 0;
		for(int i = 0; i < n; i++){
			cin >> e >> p >> q;
			r[e] += p * q;
			//r[e] = r[e] + p*q;
		}
		for(int i = 1; i <= 4000; i++){
			if(r[i] >= 1000000){
				cout << i << endl;
				tf = 1;
			}
		}
		if(tf != 1){
				cout << "NA" << endl;
			}
	}
	
	return 0;
}

C++: #include <iostream>

using namespace std;

void Solution()
{
	while(true)
	{
		int n;
		int count = 0;
		int number, perPrice, amount;

		cin>>n;

		int m = n;

		if (n == 0)
		{
			break;
		}

		while(n--)
		{
			cin>>number>>perPrice>>amount;

			long long allValue = perPrice * amount;
			
			if ( allValue >= 1000000)
			{
				cout<<number<<endl;
			}
			else
			{
				count++;
			}

			if (count == m)
			{
				cout<<"NA"<<endl;
			}
		}
	}
}

int main()
{
	Solution();
	return 0;
}

C++: #include <iostream>
using namespace std;
int main(){
	long x,y;
	int n,num,cnt=0,sum=0;
	while(cin>>n&&n!=0){
		cnt=0,sum=0;
		bool a[4000]={0};
		long p[4000]={0};
		for(int i=0;i<n;i++){
			cin>>num>>x>>y;
			if(a[num]==0)cnt++;
			a[num]=1,p[num]+=x*y;
		}
		for(int i=1;i<=4000;i++){
			if(a[i]==1&&p[i]>=1000000){
				cout<<i<<endl;
			}else if(a[i]==1){
				sum++;
			}
			if(cnt==sum){
				cout<<"NA"<<endl;
				break;
			}
		}
	}
	return 0;
}

C++: #include <cstdio>
#include <map>
using namespace std;
typedef long long ll;
 
int n;
 
int main(){
	while(scanf("%d", &n),n){
		map<int,ll> m;
		map<int,ll>::iterator it;
		for(int i = 0; i < n; i++){
			int x; ll p, q;
			scanf("%d%lld%lld", &x, &p, &q);
			m[x] += p*q;
		}
		bool ok = true;
		for(it = m.begin(); it != m.end(); it++){
			if(it->second >= 1000000){
				ok = false;
				printf("%d\n", it->first);
			}
		}
		if(ok) printf("NA\n");
	}
	return 0;
}

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

#define TAR 1000000

int main() {
	unsigned long n,num,t,k;
	while(cin >> n){
		while(n--){
			scanf("%ld %ld %ld",&num,&t,&k);
			if((k >= TAR/t)&&(TAR%t == 0)){
				cout << num << endl;
			}else if((t >= TAR/k)&&(TAR%k == 0)){
				cout << num << endl;
			}else if((k > TAR/t)&&(t > TAR/k)){
				cout << num << endl;
			}
		}
	}
	return 0;
}

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

using namespace std;

int main()
{
    const int TARGET = 1000000;
    map<int, int> sale;
    int n_data, id, amount, price, n_target;
    for (;;) {
	cin >> n_data;
	if (n_data == 0)
	    break;
	for (int i = 0; i != n_data; ++i) {
	    cin >> id >> price >> amount;
	    sale[id] += price * amount;
	}
	map<int, int>::iterator it = sale.begin();
	n_target = 0;
	while (it != sale.end()) {
 	    if (it->second >= TARGET) {
		cout << it->first << endl;
		++n_target;
	    }
	    ++it;
	}
	if (n_target == 0)
	    cout << "NA" << endl;
	sale.clear();
    }
}