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 <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 2000000000
#define EQ(a,b) (abs((a)-(b))<EPS)
int main()
{
	ll u[4010];
	vector<int> v;
	bool k;
	while(1)
	{
		for(int i=0;i<4010;i++)
		{
			u[i]=0;
		}
		k=true;
		int n;
		cin >> n;
		if(n==0)break;
		for(int i=0;i<n;i++)
		{
			int x,y,z;
			cin >> x >> y >> z;
			u[x]+=(ll)y*(ll)z;
		}
		for(int i=0;i<4010;i++)
		{
			if(u[i]>=1000000)
			{
				k=false;
				cout << i << endl;
			}
		}
		if(k)
		{
			cout << "NA" << endl;
		}
	}
	return 0;
}

C++: #include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <sstream>
using namespace std;

#define REP(i,a,n) for(i=a; i<n; i++)
#define rep(i,n) REP(i,0,n)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define foreach(it,x) for(typeof(x.begin()) it=x.begin(); it!=x.end(); it++)

/*
  AOJ :: 0100
  http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0100&lang=jp
 */

typedef long long ll;

int main(){
    int n,num,tanka,count,i;
    set<pair<int,int> > S;
    map<int,int> mii;

    while( cin >> n, n ){
        // init
        S.clear(); mii.clear();

        rep(i,n){
            cin >> num >> tanka >> count;
            if( mii.count(num) == 0 ){
                mii[num] = i;
            }
            if( (ll)tanka * (ll)count >= 1000000 && S.count(make_pair(mii[num],num)) == 0 ){
                S.insert(make_pair(mii[num],num));
            }
        }

        if( S.size() == 0 ){
            puts("NA");
        }
        else{
            foreach(it,S){
                printf("%d\n",it->second);
            }
        }
    }

    return 0;
}

C++: #include<cstdio>
#include<iostream>
using namespace std;
main(){
  int n,i,l,a,k,u,s[4000];
  while(1){
    cin >> n;
    if(n==0){
      break;
    }
    l=0;
    for(i=0;i<n;i++){
      cin >> a >> k >> u;
      if(1000000<=k*u){
	s[l]=a;
	l++;
      }
    }
    if(l==0){
      cout << "NA" << endl;
    }
    else{
      for(i=0;i<l;i++){
	cout << s[i] << endl;
      }
    }
  }
}

C++: int main(){
	int n;
	while (cin >> n)
	{	bool f = false;
		int e[4000], p[4000], q[4000], t[4000];
		for (int i = 0; i < n; i++)
		{
			cin >> e[i];
			cin >> p[i];
			cin >> q[i];
			t[i] = p[i] * q[i];
		}

		for (int a = 0; a < n; a++)
		{
			if (t[a] >= 1000000)
			{
				cout << e[a] << endl;
				f = true;
			}
		
		
		}
		if (!f)
		{
			cout << "NA" << endl;
		}
	}
	return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
  int n,a,p,c;
  while(std::cin>>n,n){
		vector<int> v;
		vector<int>::iterator it;
    for(;n;n--){
      cin>>a>>p>>c;
      it=find(v.begin(),v.end(),a);
      if(p*c>=1000000&&it==v.end())v.push_back(a);
    }
    if(v.empty())cout<<"NA"<<endl;
    else{
    it = v.begin();
    while(it!=v.end()){
      cout<<*it<<endl;
      it++;
    }
    }
  }
}

C++: #include<cstdio>
#include<map>
#include<vector>
std::map<int, long long> mp;
std::vector<int> v;
int main() {
	int n, i, e;
	long long p, q;
	while (true) {
		scanf("%d", &n);
		if (n == 0)break;
		for (i = 0; i < n; i++) {
			scanf("%d%lld%lld", &e, &p, &q);
			if (mp.count(e) == 0) mp[e] = p*q;
			else mp[e] += p*q;
		}
		for (std::map<int, long long>::iterator itr = mp.begin(); itr != mp.end(); ++itr) {
			if (itr->second >= 1000000)v.push_back(itr->first);
		}
		if (v.size() == 0)printf("NA\n");
		else {
			for (std::vector<int>::iterator itr = v.begin(); itr != v.end(); ++itr) {
				printf("%d\n", *itr);
			}
		}
		mp.clear();
		v.clear();
	}
	return 0;
}

C++: #include<iostream>
#include<cstdio>
using namespace std;
int main(){
 long long int n,num,mon,cont,a[4001],nacount;
  while(scanf("%d",&n)!=EOF){
    if(n==0){break;}
    for(int i=0;i<4001;i++){
      a[i]=0;
    }
    nacount=0;
    for(int i=0;i<n;i++){
      cin>>num>>mon>>cont;
      a[num]+=mon*cont;
    }
    for(int i=1;i<4001;i++){
      if(a[i]>=1000000){
	cout<<i<<endl;
	nacount++;
      }
    }if(nacount==0){
      cout<<"NA"<<endl;
    }
  }
  return 0;
}

C++: #include<iostream>
using namespace std;
int main()
{
	int n;
	int number[4000]={0};
	int tanka;
	int ryou;
	long goukei[4000]={0};
	while(cin>>n,n){
		for(int i=0;i<n;i++){
			cin>>number[i];
			cin>>tanka;
			cin>>ryou;
			goukei[i]=tanka*ryou;
		}
		for(int i=0;i<n-1;i++){
			for(int j=i+1;j<n;j++){
				if(number[i]==number[j]){
					goukei[i]+=goukei[j];
					goukei[j]=0;
					}
			}
		}
		int flag=-1;
		for(int i=0;i<n;i++){
			if(goukei[i]>=1000000){
				flag=0;
				cout<<number[i]<<endl;
				}
		}
		if(flag==-1)
			cout<<"NA"<<endl;
	}
	return 0;
}

C++: #include<stdio.h>

int main(){

	int n, i, x[4000] = {}, xx[4000] = {}, xxx[4000] = {}, r, y = 0, w;
	scanf("%d", &n);
	for (w = 0; w < n; w++){

		for (i = 0; i < n; i++){
			scanf("%d %d %d",&x[i],&xx[i],&xxx[i]);
		}
		for (r = 0; r < 4000; r++){
			if (xx[r] * xxx[r] > 1000000){
				printf("%d\n", x[r]);
			}	
		}if (y == 0){ printf("NA\n"); (y = 0); }		scanf("%d", &n);
	}
	return 0;
}

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

int main()
{
	while ( true )
	{
		int n; cin>>n;
		if ( n == 0 )
			break;
		vector<pair<int,long long> > E;

		for ( int i=0; i<n; i++ )
		{
			int a, b, c;
			cin>>a>>b>>c;
			int j;
			for ( j=0; j<(int)E.size(); j++ )
				if ( E[j].first==a )
					break;
			if ( j==(int)E.size() )
				E.push_back( make_pair(a,0ll) );
			E[j].second += (long long)b*c;
		}
		bool f = false;
		for ( int i=0; i<(int)E.size(); i++ )
			if ( E[i].second >= 1000000 )
				cout << E[i].first << endl,
				f = true;
		if ( ! f )
			cout << "NA" << endl;
	}
}

C++: #include <iostream>
using namespace std;
typedef long long ll;
//vector<pair<bool, ll>> v(4001);
unsigned long long int a[4001];

int main(){
	int n, num, p, q;
	while(cin >> n, n){
		//fill(a, a+4001, 0);
		for(int i = 0;i < 4001;i++)a[i] = 0;
		for(int i = 0;i < n;i++){
			cin >> num >> p >> q;
			a[num] += p * q;
		}
		int f = 1;
		for(int i = 1;i <= 4000;i++)if(a[i] >= 1000000)cout << i << endl, f = 0;
		if(f)cout << "NA" << endl;
	}
	return 0;
}

/*
4
1001 2000 520
1002 1800 450
1003 1600 625
1001 200 1220
*/