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<vector>
#include<list>
#include<algorithm>
#include<iostream>
#include<string>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
int main(){
  int i;
  int n,b,m,s,l,d[4000];
  for(;;){
    cin>>n;
    if(n==0)
      break;
    l=0;
    for(i=0;i<n;i++){
      cin>>b>>m>>s;
      if((long long)m*(long long)s>=1000000){
	d[l]=b;
	l++;
      }
    }
    if(l){
      for(i=0;i<l;i++)
	cout<<d[i]<<endl;
    }else
      cout<<"NA"<<endl;
  }
  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)

int main(void){
    int n, i;
    long long int p, q;
    map<int, long long int> emp;
    vector<int> seq;
    while(cin >> n && n) {
        bool isExist = false;
        emp.clear();
        seq.clear();
        rep(l, n) {
            cin >> i >> p >> q;
            if(!emp[i]) seq.push_back(i);
            emp[i]+=p*q;
        }
        rep(i, seq.size()) {
            if(emp[seq[i]] >= 1000000) {
                cout << seq[i] << endl;
                isExist = true;
            }
        }
        if(!isExist) cout << "NA" << endl;
    }
}

C++: 
#include<iostream>
#include<string>
#include<cmath>
#include<vector>
#include<stack>
#include<queue>
#include<algorithm>
#include<complex>
using namespace std ;
typedef vector<int> vi ;
typedef vector<vi> vvi ;
typedef vector<string> vs ;
typedef pair<int, int> pii; 
typedef long long ll ;

#define loop(i,a,b) for(int i = a ; i < b ; i ++)
#define rep(i,a) loop(i,0,a)
#define all(a) (a).begin(),(a).end()


int main(void){
	int n;	
	while(cin>>n,n){
		vvi num(n,vi(3,0));
		rep(i,n){
			//cout<<num[i][0]<<" "<<num[i][1]<<endl;
			cin>>num[i][0];
			int item,code;
			rep(j,i){
				if(num[i][0]==num[j][0]){
					num[j][1]+=item*code;
					num[i][2]=1;
				}
			}
			cin>>item>>code;
			if(!num[i][2])num[i][1]+=item*code;
		}
		//cout<<"star"<<endl;
		int cnt=0;
		vi ans;
		rep(i,n){
			//cout<<num[i][0]<<" "<<num[i][1]<<endl;
			if(num[i][1]>=1000000){ans.push_back(num[i][0]);cnt++;}
		}
		sort(all(ans));
		rep(i,ans.size())cout<<ans[i]<<endl;
		if(!cnt)cout<<"NA"<<endl;
		//cout<<"NO"<<n<<endl<<endl;;
	}
}

C++: #include<iostream>
using namespace std;
int main(void) {
	int a, b, c,d,e=0,f=0;
	while(1){
		cin >> a;
		if (a == 0) break;
		while (1) {
			cin >> b >> c >> d;
			if (c*d >= 1000000) {
				cout << b << endl;
				e++;
			}
			f++;
			if (a == f) break;
		}
		if (e == 0) cout << "NA\n";
		f = 0;
		e = 0;
	}
}

C++: #include<stdio.h>


int main(){
	int n;
	int id[4000],cid;
	long long int price,num,sale[4000];
	bool f;
	int i,j,idcount;
	while(scanf("%d",&n),n){

		f=true;
		idcount=0;

		for(i=0;i<n;i++){
			scanf("%d %lld %lld",&cid,&price,&num);
			for(j=0;j<idcount;j++){
				if(id[j]==cid){
					sale[j]=sale[j]+price*num;
				}
			}

			if(j==idcount){
				id[idcount]=cid;
				sale[idcount]=price*num;
				idcount++;
			}

		}



		for(i=0;i<idcount;i++){
			if(sale[i]>=1000000){
				printf("%d\n",id[i]);
				f=false;
			}
		}
		if(f!=false)printf("NA\n");
	}
	return 0;
}

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

int main() {
	int n,id,i,f,a,b,da[4001];
	while (cin >> n) {
		if (n==0) break;
		memset(da,0,sizeof(da));
		for (i=0;i<n;i++) {
			cin >> id >> a >> b;
			da[id]+=a*b;
			}
		f=0;
		for (i=1;i<=4000;i++) if (da[i]>=1000000) { cout << i << endl; f=1; }
		if (f==0) cout << "NA" << endl;
	}
	return 0;
}

C++: /*Kim Jong Il*/

#include<iostream>
#include<cstdio>
#define N1 1000
using namespace std;

int main(){
  int n,id[N1],array[N1][N1],i,j,count;
  
  while(1){
    count = 0;
    cin >> n;
    if(n == 0)break;
    
    for(i=0;i<n;i++){
      cin >> id[i];
      for(j=0;j<2;j++){
	cin >> array[i][j];
      }
    }
    for(i=0;i<n;i++){
      if(array[i][0] * array[i][1] >= 1000000){
	cout << id[i] << endl;
	count++;
      }
    }
    if(count == 0)cout << "NA" << endl;   
  }
}

C++: #include <iostream>

#define N 1000000

using namespace std;

int main(){
	int n;
	while(cin >> n){
		if(!n) break;
		bool chk = 0;
		for(int i = 0; i < n; i++){
			int num, val, sum;
			cin >> num >> val >> sum;
			double tmp = val * sum;
			if(tmp >= N){
				chk = 1;
				cout << num << endl;
			} 
		}
		if(!chk) cout << "NA" << endl;
	}
	return 0;
}

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

using namespace std;

int n;
long long id[4000];
long long value[4000];
long long number[4000];
map<long long, long long> total;

int main() {
  while(true){
    cin >> n;
    if(n==0){
        return 0;
    }
    for (int i = 0; i < n; i++) {
        cin >> id[i] >> value[i] >> number[i];
        if(total.find(id[i])==total.end()){
          total.insert(make_pair(id[i], 0));
        }
        total[id[i]] += value[i] * number[i];
    }
    vector<long long> v;
    if(!total.empty()) {
        map<long long, long long>::iterator it = total.begin();
        while (it != total.end()) {
            if ((*it).second >= 1000000) {
                v.push_back((*it).first);
            }
            ++it;
        }
    }
    if (v.empty()) {
        cout << "NA" << endl;
    }
    for (vector<long long>::iterator it = v.begin(); it != v.end(); ++it) {
        cout << *it << endl;
    }
    v.clear();
    total.clear();
  }
}

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

using namespace std;
typedef long long ll;

int main(void) {
    int n, e, flag = 0;
    ll p, q;

    while (scanf("%d", &n), n) {
        vector<int> v;
        map<int, ll> mp;
        for (int i = 0; i < n; i++) {
            scanf("%d %lld %lld", &e, &p, &q);
            if (!mp[e]) v.push_back(e);
            mp[e] += p * q;
        }

        flag = 0;
        for (int i = 0; i < v.size(); i++) {
            if (mp[v[i]] < 1000000) continue;
            printf("%d\n", v[i]);
            flag = 1;
        }
        
        if (!flag) puts("NA");
    }
    return 0;
}

C++: #include <iostream>
#include <string.h>

using namespace std;

int N, M;

int main() {
	long long  goal = 1000000;

	for (; cin >> N;) {
		if (!N) break;
		long long  v[4000];
		memset(v, 0, sizeof(v));
		for (int i = 0; i < N; i++) {
			long long  e, p, q;
			cin >> e >> p >> q;
			v[e - 1] += p*q;
		}
		bool flag = false;
		for (int i = 0; i < 4000; i++) {
			if (v[i] >= goal) {
				flag = true;
				cout << i + 1 << endl;

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

	return 0;
}

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<time.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define rp(a) while(a--)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
int main(){
	int n;
	while(cin>>n,n){
		map<ll,ll>in;
		rep(i,n){
			ll a,b,c;
			cin>>a>>b>>c;
			in[a]+=b*c;
		}
		bool h=false;
		for(map<ll,ll>::iterator it=in.begin();it!=in.end();it++){
			ll d=it->first;
			if(in[d]>=1e6){
				h=true;
				cout<<d<<endl;
			}
		}
		if(!h)cout<<"NA"<<endl;
	}
}