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 <queue>
#include <map>

int n, e, p, q;

int main(){
    while(1){
        scanf("%d", &n);
        if(!n) break;

        std::map<int, int> m;
        std::queue<int> que;

        for(int i = 0; i < n; i++){
            scanf("%d %d %d", &e, &p, &q);

            if(m.count(e) != 0){
                m[e] += (p * q);
            }else{
                m[e] = p * q;
                que.push(e);
            }
        }

        bool flag = true;
        while(!que.empty()){
            int tmp = que.front(); que.pop();

            if(m[tmp] >= 1000000){
                printf("%d\n", tmp);
                flag = false;
            }
        }

        if(flag){
            printf("NA\n");
        }
    }

    return 0;
}

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

#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;

int main()
{
	long long int value[4001];

	int n,num,k,m;
	while(cin >> n && n)
	{
		memset(value,0,sizeof(value));

		rep(i,n)
		{
			cin >> num >> k >> m;
			value[num] += k*m;
		}

		bool flag = true;
		rep(i,4001)
		{
			if(value[i] >= 1000000)
			{
				flag = false;
				cout << i << endl;
			}
		}

		if(flag) cout << "NA" << endl;
	}
	return 0;
}

C++: #include <iostream>
using namespace std;
int main(){
  int i, n, q;
  long long int p;
  while(cin >> n, n){
    bool NAflg = false;
    while(n--){
      cin >> i >> p >> q;
      if((p * q) >= static_cast<int>(1e6)){
	cout << i << endl;
	NAflg = true;
      }
    }
    if(!NAflg)
      cout << "NA" << endl;
  }
  return 0;
}

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

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

C++: #include<stdio.h>
#include<string.h>
#include<math.h>
int main(void)
{
	long long int g[1001],s[1001],d[1001],f[1001];
	int j,i,k,a,h[1001];
	while(1){
		scanf("%d",&a);
		if(a==0) break;
		for(i=0;i<a;i++){
			h[i]=0;
			g[i]=0;
		}
		for(i=0;i<a;i++){
			scanf("%lld %lld %lld",&s[i],&d[i],&f[i]);
			if(d[i]*f[i]>=1000000) h[i]=1;
			if(d[i]==1000000&&f[i]>=1) h[i]=1;
			if(f[i]==100000&&d[i]>=10) h[i]=1;
			if(h[i]==0) g[i]=d[i]*f[i];
			else g[i]=0;
		}
		for(i=0;i<a;i++){
			for(j=i+1;j<a;j++){
				if(g[i]>=1000000&&h[i]==0){
					h[i]=1;
				}
				if(s[i]==s[j]){
					if(h[i]==0){
						g[i]+=g[j];
						g[j]=0;
					}
					else g[j]=0;
				}
				if(g[i]>=1000000&&h[i]==0){
					h[j]=1;
				}
			}
		}
		k=0;
		for(i=0;i<a;i++){
			if(h[i]==1){
				printf("%lld\n",s[i]);
				k=1;
			}
		}
		if(k==0) printf("NA\n");
	}
	return 0;
}

C++: #include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
int main(){
    int n;
    queue<int> q;   
    while(cin >> n){
        if(n==0) break;
        map<int,ll> data;
        vector<int> memo(n);
        rep(i,n){
            int number;
            cin >> number;
            memo[i] = number;
            ll p,q;
            cin >> p >> q;
            data[number] += (p*q);
        }
        bool ok = false;
        rep(i,n){
            if(data[memo[i]] >= 1000000){ q.push(memo[i]); ok = true; data[memo[i]]=0; }
        }
        if(!ok) q.push(-1);
    }
    while(!q.empty()){
        if(q.front()<0) cout << "NA" << endl;
        else cout << q.front() << endl;
        q.pop();
    }
    return 0;
}

C++: #include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int dx[] = { -1, 0, 1, 0 }; const int dy[] = { 0, 1, 0, -1 };
struct salary{
	int no;
	long long sell;
	bool b;
};

int main() {
	
	int n;
	while(cin>>n,n){
		vector<salary> vs;
		REP(i, n){
			int no, sell_n, value;
			cin >> no >> sell_n >> value;
			bool b = false;
			REP(j, vs.size()){
				if (vs[j].no == no){
					b = true;
					vs[j].sell += sell_n*value;
					if (vs[j].sell >= 1000000){
						vs[j].b = true;
					}
				}
			}
			if (!b)vs.push_back({ no, sell_n*value ,false});
		}
		bool b2=false;
		REP(i, vs.size()){
			if (vs[i].b){
				cout << vs[i].no << endl;
				b2 = true;
			}
		}
		if (!b2)cout << "NA"<< endl;
	}
}