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++: #include <bits/stdc++.h>

using namespace std;

int main(){

  long long n, id, val, num, cnt;
  long long member[4000];
  int index[4000];

  while(cin >> n){

    if(!n) break;

    cnt = 0;
    memset(member, -1, sizeof(member));
    memset(index, -1, sizeof(index));

    for(int i = 0; i < n; ++i){

      cin >> id >> val >> num;

      if(member[id - 1] == -1){
        index[cnt] = id - 1; ++cnt;
        member[id - 1] += 1 + val * num;
      } else {
        member[id - 1] += val * num;
      }

    }

    bool flag = false;

    for(int i = 0; i < cnt; ++i){
      if(member[index[i]] >= 1000000){
        cout << index[i] + 1 << endl;
        flag = true;
      }
    }

    if(!flag) cout << "NA" << endl;

  }

}

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

int main()
{
	while(true){
		int n;
		cin >> n;
		if(n==0)
			break;

		int num,x,y;
		int mon=0,cnt=0;
		int p[4000];
		int j=0;

		for(int i=0 ;i<n ;i++)
			p[i] = 0;

		for(int i=0 ;i<n ;i++){
			cin >> num >> x >> y;

			mon = x*y;
			if(mon >=1000000){

				p[j] = num;
				cnt++;
				j++;
			}
		}
		if(cnt > 0){
			for(int i=0 ;i<cnt ;i++)
				cout << p[i] << endl;
		}
		if(cnt==0)
			cout << "NA" << endl;

	}
	return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cstdio>
#include <math.h>
#include <map>
#include <queue>
#include <string>
using namespace std;

typedef long long ll;

int s[4000][2],n,a,b,N;
string d;

int main(){
    while(cin>>N){
	if(N==0)return 0;
	for(int i=0;i<4000;i++){
	    for(int j=0;j<2;j++){
		s[i][j]=0;
	    }
	}
	int m=0;
	for(int i=0;i<N;i++){
	    cin>>n>>a>>b;
	    int flag=0;
	    for(int j=0;j<m;j++)if(s[j][0]==n){s[j][1]+=a*b;flag=1;}
	    if(flag==0){s[m][0]=n;s[m][1]=a*b;m++;}
	}
	int flag2=0;
	for(int i=0;i<4000;i++)if(s[i][1]>999999){cout<<s[i][0]<<endl;flag2=1;}
	if(flag2==0)cout<<"NA"<<endl;
    }
}

C++: #include <cstdio>
#include <iostream>
#include <vector>
#include <utility>
typedef long long ll;
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); ++i)
int main() {
	ll n;
	while(scanf("%d\n", &n), n){
		vector<pair<ll, ll> > v;
		rep(i,n) {
			ll x, y, z;
			cin >> x >> y >> z;
			bool f = false;
			for(ll j = 0; j < v.size(); ++j) {
				if(v[j].first == x) {
					v[j].second += (ll) y * z;
					f = true;
					break;
				}
			}
			if(!f) {
				v.push_back(make_pair(x, (ll)(y * z)));
			}
		}
		bool flag = false;
		for(ll j = 0; j < v.size(); ++j) {
			if(v[j].second >= 1000000) {
				flag = true;
				cout << v[j].first << endl;
			}
		}
		if(!flag) cout << "NA" << endl;
	}
	return 0;
}

C++: #include <iostream> 
#include <string> 
#include <vector> 
#include <cmath> 
#include <algorithm> 
#include <cstdlib> 

using namespace std;

int main()
{
	int n,f,b;
	long long c,d;

	while(1){
		f=1;int k=0;
		int a[4000][2]={0};
		cin>>n; if(n==0) return 0;

		for(int i=0;i<n;i++){
			cin>>b>>c>>d;
			for(int j=0;j<k;j++){
				if(a[j][0]==b && a[j][1]>0){ a[j][1]+=c*d; f=0;}
			}
			if(f){
				a[k][0]=b; a[k++][1]=c*d;
			}
		}

		f=0;
		for(int i=0;i<k;i++){
			if(a[i][1]>=1000000) {cout<<a[i][0]<<endl; f=1;}
		}
		if(f) cout<<"NA"<<endl;
	}
}

C++: #include<stdio.h>

int main(void) {
	long long int a, b, count = 1, number = 0, syain[4010], tanka[4010], suuryou[4010], score[4010] = {}, noruma = 1000000, sens = 0;
	while (count) {
		sens = 0;
		long long int score[4010] = {};
		scanf("%d", &count);
		for (size_t i = 0; i < count; i++)
		{
			scanf("%lld %lld %lld", &syain[number], &tanka[number], &suuryou[number]);
			score[syain[number]] += tanka[number] * suuryou[number];
			if (score[syain[number]] >= noruma)
			{
				printf("%lld\n", syain[number]);
				sens++;
			}
			number++;
		}
		if (sens == 0 && count != 0)
		{
			printf("NA\n");
		}
	}
	return 0;
}

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

int main() {
	int n;
	while(std::cin >> n){
		if(!n){
			return 0;
		}
		std::map<int, long long> sales;
		while(n--){
			int id, unit, num;
			std::cin >> id >> unit >> num;
			sales[id] += (long long)unit * num;
		}
		map<int, long long>::iterator it;
		bool found = false;
		for(it = sales.begin(); it != sales.end(); it++){
			if(it->second >= 1000000){
				found = true;
				std::cout << it->first << std::endl;
			}
		}
		if(!found){
			std::cout << "NA" << std::endl;
		}
	}
	return 0;
}

C++: #include<stdio.h>
#include<string>
#include<iostream>
using namespace std;

struct R{
int num;
long long int su;
int k;
};

int main(){

int N,M;

while(1){

struct R n[4001];
cin>>N;if(N==0)break;
for(int i=0;i<=4000;i++)
	n[i].su=0;

for(int i=1;i<=N;i++){
	int r,q,nu;
	cin>>nu;n[nu].num=nu;cin>>r>>q;
	if(n[nu].su==0){n[nu].k=i;}
	n[nu].su+=r*q;
	
}/*
for(int i=0;i<N;i++)
	for(int j=i+1;j<N;j++)
	{if(n[i].num==n[j].num){n[i].su+=n[j].su;n[j].su=0;}
	}*/
bool f=false;
for(int i=0;i<N;i++)
for(int j=0;j<4001;j++)
	if(n[j].k==i&&n[j].su>=1000000)
	{cout<<n[j].num<<endl;f=true;}

	if(f==false)cout<<"NA"<<endl;
}
return 0;
}

	

/*


string str;int s=0;
for(int iii=0;iii<M;iii++){
	cin>>str;
	for(int i=0;i<N;i++){bool f=true;
		for(int j=0;j<8;j++)
			if((n[i].y[j]!=str[j])&&n[i].y[j]!='*'){f=false;}//cout<<n[i].y[j]<<"#"<<str[j]<<endl;}
		if(f==true)s+=n[i].C;
	}

}

cout<<s<<endl;



}
return 0;
}*/

C++: #include <iostream>
using namespace std;
int main (int argc, const char * argv[])
{

    int n=1,num,tanka,suryo;
    bool na=true;
    while(true){
        cin>>n;
        if(n==0){
            return 0;
        }
        for(int i=0;i<n;i++){
            cin>>num>>tanka>>suryo;
            if(tanka*suryo>=1000000){cout<<num<<endl;na=false;}
        }
        if(na)cout<<"NA"<<endl;
        na=true;
    }
}

C++: #include <bits/stdc++.h>
using namespace std;

typedef long int lint;
typedef long long int llint;

#define EACH(i, c) for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define ALL(c) (c).begin(), (c).end()
#define FOR(i, s, e) for (int i = (s); i < (int)(e); ++i)
#define REP(i, n) FOR(i, 0, n)
#define endl "\n"

template<typename T>
void print(const std::vector<T>& v, char sep=' ') {
  for (int i = 0; i < (int)v.size(); i++) {
    if (i != 0) cout << sep;
    cout << v[i];
  }
  cout << endl;
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  
  while (cin >> n, n){
    llint p, q;
    llint e[1010] = {0}, res[4010] = {0};
    bool judge = false;
    REP(i, n){
      cin >> e[i] >> p >> q;
      res[e[i]] += p * q;
    }
    sort(e, e + n);
    REP(i, n){
      if (res[e[i]] >= 1000000 && e[i] != e[i + 1]){
        cout << e[i] << endl;
        judge = true;
      }
    }
    if (!judge) cout << "NA" << endl;
  }
}