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<iostream>
#include<map>
using namespace std;
int main(){
  int n;
  while(cin >>n,n){
    int a;
    long long b,c;
    map<int, long long> sale;
    bool f = true;
    for(int i=0; i<n; i++){
      cin >>a>>b>>c;
      if(sale[a]+b*c > 1000000){sale[a] = 1000000;}
      else{sale[a]+=b*c;}
    }
    for(map<int,long long>::iterator pos = sale.begin(); pos!=sale.end(); pos++){
      if(pos->second >= 1000000){cout <<pos->first<<endl;f = false;}
    }
    if(f){cout <<"NA"<<endl;}
  }
  return 0;
}

C++: // a.c.cpp : ??????????????? ??¢????????±????????§????????¨????????? ?????????????????????????????????
//

#include <stdio.h>
long long int bango[4001];
int main(void){
	int n;
	long long ban, tan, suu;
	int flg,i;
	while (1){
		for (i = 1; i <= 4000; i++){
			bango[i] = 0;
		}
		scanf("%d", &n);
		if (n == 0){
			break;
		}
		for (i = 0; i < n; i++){
			scanf("%d %d %d", &ban, &tan, &suu);
			bango[ban] += tan*suu;
		}
		flg = 0;
		for (i = 1; i <= 4000; i++){
			if (bango[i]>=1000000){
				printf("%d\n", i);
				flg = 1;
			}
		}
		if (!flg){
			printf("NA\n");
		}
	}
	return 0;
}

C++: #include <stdio.h>
 
 
int n;
long long num[4000],tanka[4000],sale_num[4000];
int sale_all[4001],judge[4001];
 
int main(void){
	int i,j,k;
	
	while(scanf("%d",&n),n!=0){
		
		for(i=0;i<n;i++){
			scanf("%d%d%d",&num[i],&tanka[i],&sale_num[i]);
			
		}
		
		//初期化
		k=0;
		for(j=0;j<=4001;j++){
			judge[j]=0;
			sale_all[j]=0;
		}
		
		//idに対応したsaleに+
		for(i=0;i<n;i++){
			sale_all[num[i]] = sale_all[num[i]]+ tanka[i]*sale_num[i];
		}
		
		for(i =0; i < n; i++){
			if((sale_all[num[i]] >= 1000000)&&(judge[num[i]]==0)){
				printf("%d\n",num[i]);
				judge[num[i]]=1;
				k=1;
			}
		}
		
		if(k!=1)printf("NA\n");
	}
	
	return 0;
}

C++: #define _USE_MATH_DEFINES
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <cassert>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>
#include <iomanip>
#include <iterator>

using namespace std;

typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;

 
int main(){
	int n;
	while(cin>>n,n){
		vector<int> a;
		for (int i = 0; i < n; i++){
			int d,b,c; cin>>d>>b>>c;
			if(b*c >= 1000000) a.push_back(d);
		}
		if(a.size() == 0){ puts("NA"); continue; }
		for (int i = 0; i < a.size(); i++)
			cout << a[i] << endl;
	}
    return 0;
}

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

#define SHINE_MAX 4000
#define ELITE 1000000
#define AHO "NA"

int shineN,eliteN;
long int shineU[SHINE_MAX];	//?£??????????

int num,tanka,suryo;
int i;

int main(){
	while(1){
	 cin>>shineN;
	 if(shineN==0){break;}
	 for(i=0;i<SHINE_MAX;i++){shineU[i]=0;}
	 for(i=0;i<shineN;i++){
	  cin>>num,tanka,suryo;
	  shineU[num-1]+=tanka*suryo;
	 }
	 //??¨?????????????????¨
	 eliteN=0;
	 for(i=0;i<SHINE_MAX && eliteN<shineN;i++){
	  if(ELITE<=shineU[i]){
	   cout<<i<<endl;
	   eliteN++;
	  }
	 }
	 if(eliteN==0){cout<<AHO<<endl;}
	}
	return 0;
}

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

template<typename itr, typename func>
func for_each_withindex(itr fi, itr l, func f){
	unsigned i{};
	for(; fi!=l; ++fi,++i){
		f(*fi,i);
	}
	return f;
}

int main(int argc, char const* argv[])
{
	unsigned n{};
	while (std::cin >> n,n != 0) {
		unsigned long long e{}, p{}, q{};
		bool isna{true};
		std::array<unsigned long long,4001> es{};
		for (unsigned i = 0; i < n; i++) {
			std::cin >> e >> p >> q;
				es.at(e) += p * q;
		}
		for_each_withindex(es.begin(), es.end(), [&isna](auto sell,auto e){ 
				if (sell>=1000000) {
				std::cout << e << std::endl;
				isna = false;
				}});
		if (isna) {
			std::cout << "NA" << std::endl;
		}

	}
	return 0;
}

C++: #include <stdio.h>
 
int n,num[4000];
long long int tanka[4000],sale_num[4000],sale_all[4001];
bool judge[4001];
 
int main(void)
{
int i,j,k;
     
while(scanf("%d",&n),n){
    for(i=0;i<n;i++){
        scanf("%lld %lld %lld",&num[i],&tanka[i],&sale_num[i]);
    }
    k=0;
    for(j=0;j<4001;j++){
    judge[j]=0;
    sale_all[i]=0;
    }
    for(i=0;i<n;i++){
        sale_all[num[i]] = sale_all[num[i]]+ tanka[i]*sale_num[i];
    }
    for(i=0; i < n; i++){
        if((sale_all[num[i]] >= 1000000)&&(judge[num[i]]==0)){
            printf("%d\n",num[i]);
            judge[num[i]]=1;
            k=1;
        }
    }
    if(k!=1)printf("NA\n");
}
 
    return 0;
}

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

int loop(int h, int u);

int main(){
    int id, h, u, n;
    while(cin >>n){
        if(n == 0) break;
        bool flg = false;
        for(int i = 0; i < n; i++){
            cin >>id >>h >>u;
            if(loop(h, u)){
                cout <<id <<endl;
                flg = true;
            }
        }
        if(!flg) cout <<"NA" <<endl;
    }
    return 0;
}

int loop(int h, int u){
    int sum = 0;
    for(int i = 0; i < u; i++){
        sum += h;
        if(sum >= 1000000) return 1;
    }
    return 0;
}

C++: #include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
    long long int aa[10000]={0},x=0,y=0,z=0,flg=0,a,flgg[4050]={0};
    while(cin>>a)
    {
        if(a==0)break;
        for(int i=0;i<a;i++)
        {
            cin>>x>>y>>z;
            aa[x]+=y*z;
            if(aa[x]>=1000000)
            {
                if(flgg[x]==0)
                {
                    cout<<x<<endl;
                }
            }
        }
        //for(int i=0;i<4010;i++)
        //{
        //    if(aa[i]>=1000000)
        //    {
        //        flg=1;
        //        cout<<i<<endl;
        //    }
        //}
        if(flg==0)cout<<"NA"<<endl;
        for(int i=0;i<4010;i++)
        {
            aa[i]=0;
            flg=0;
        }
    }
    return 0;
}

C++: #include<iostream>
#include<vector>
#include<map>
#include<cstdio>
#define int long long
using namespace std;

class Input {
public:
	int n;
	vector<int> numbers, tanka, num;
	
	bool input() {
		scanf("%d", &n);
		if (!n) {
			return false;
		}
		for (int i = 0; i < n; i++) {
			int s, t, u;
			scanf("%d%d%d", &s, &t, &u);
			numbers.push_back(s);
			tanka.push_back(t);
			num.push_back(u);
		}
		return true;
	}
};
class Solver : public Input {
public:

	vector<int> solve() {
		typedef pair<int, int> P;
		map<int, int> data;
		for (int i = 0; i < n; i++) {
			int value = tanka[i] * num[i];
			int number = numbers[i];
			
			if (data.find(number) == data.end() ) {
				data[number] = 0;
			}
			data[number] += value;
		}
		
		vector<int> ret;
		for (map<int, int>::iterator it = data.begin(); it != data.end(); it++) {
			if ((*it).second >= 1000000 ) {
				ret.push_back((*it).first);
			}
		}
		return ret;
	}
};

signed main() {
	while (true) {
		Solver solver;
		if (!solver.input() ) {
			break;
		}
		
		vector<int> res = solver.solve();
		if (res.size() == 0) {
			cout << "NA" << endl;
		}
		else {
			for (int i = 0; i < res.size(); i++) {
				cout << res[i] << endl;
			}
		}
	}
	return 0;
}