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<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
using namespace std;
void shoki();
void henkan(string);
void shoki2();
int tansaku(int);
pair<string,long long> num[10000];
int n,ban,tanka,kazu,i,j,memo;
bool dp[10000]={false};
int main(){
	int al=0;
	bool y=false;
	while(1){
		shoki();
		cin>>n;
		if(n==0){
			break;
		}
		int count=0;
		for(i=0;i<n;i++){
			cin>>num[i].first>>tanka>>kazu;
			henkan(num[i].first);
			if(dp[memo]==true){
				num[tansaku(i)].second+=tanka*kazu;
			}
			else{
			num[i].second+=tanka*kazu;
			}
			dp[memo]=true;
			memo=0;
		}
		for(int k=0;k<=i;k++){
			if(num[k].second==0){
				continue;
			}
			if(num[k].second>=1000000){
				y=true;
				cout<<num[k].first<<endl;
			}
		}
		if(y==false){
			cout<<"NA"<<endl;
		}
		y=false;
		shoki();
		shoki2();
	}
	return 0;
}
void shoki(){
	for(int i=0;i<4001;i++){
		num[i].first="0";
		num[i].second=0;
	}
	return;
}
void henkan(string str1){
	long long kake=1;
	for(int i=0;i<str1.size();i++){
		memo+=str1[i]*i;
		i*=10;
	}
	return;
}
int tansaku(int rec){
	int res;
	for(int l=0;l<rec;l++){
		if(num[rec].first==num[l].first){
			return res=l;
		}
	}
}
void shoki2(){
	for(int i=0;i<10000;i++){
		dp[i]=0;
	}
	return;
}

C++: #include <algorithm>
#include <cmath>
#include <ctime>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
#include <cstring>
#include <tuple>
#include <bitset>
#include <unordered_map>
using namespace std;
typedef long long ll;
int main() {
    ios::sync_with_stdio(false);

    int n;
    while (cin >> n && n) {
        map<int,int> sum;
        for (int i=0; i<n; ++i) {
            int no, price, quantity;
            cin >> no >> price >> quantity;
            sum[no] += price * quantity;
        }

        bool NA = true;
        for (map<int,int>::iterator it = sum.begin(); it != sum.end(); ++it) {
            if (it->second >= 1000000) {
                cout << it->first << endl;
                NA = false;
            }
        }
        if (NA)
            cout << "NA" << endl;
    }
    return 0;
}

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

int n;
int main(){
	cin >> n;
	int id[n];
	int p[n];
	int q[n];
	int num = 0;
	for(int i = 0; i < n; i++){
		cin >> id[i] >> p[i] >> q[i];
		if(p[i] * q[i] >= 1000000){
			cout << id[i] << "\n";
			num++;
		} 
	}
	if(num == 0){
		cout << "NA";
	} 
    return 0;
}

C++: #include<iostream>

using namespace std;

int main()
{
	int n,ans[4000];
	double a,b;
	
	for(;;)
	{
		cin >> n;
		if(n==0)
			break;
		int i,j;
		for(i=0,j=0;i<n;i++)
		{
			int num,flag=1;
			cin >> num >> a >> b ;
			if(a/1000000.0*b>=1.0)
			{
				for(int k=0;k<j;k++)
				{
					if(ans[k]==num)
						flag=0;
				}
				if(flag==1)
				{
					ans[j]=num;
					j++;
				}
			}
		}
		
		if(j!=0)
		{
			for(int i=0;i<j;i++)
			{
				cout << ans[i] << endl;
			}
		}
		else
			cout << "NA" << endl;
	}
}

C++: #include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
int st[4444];
int stf[4444];
int main(void)
{
  while(1){
    int n;
    bool f = true;
    cin >> n;
    if(!n) break;
    memset(st,0,sizeof(st));
    memset(stf,-1,sizeof(stf));
    for(int i = 0; i < n; i++){
      int a,b,c;
      cin >> a >> b>> c;
      st[a] += b * c;
      if(1000000 <= st[a] && stf[a]){
	cout << a << endl;
	stf[a] = 0;
	f = false;
      }
    }
    if(f) puts("NA");
  }
}

C++: #include <cstdio>
#include <cstdlib>
#include <cmath>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <cstring>
#include <functional>

using namespace std;

#define REP(i,a,b) for((i)=(a);(i)<(int)(b);(i)++)
#define rep(i,n) REP(i,0,n)
#define foreach(itr,c) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
#define ll long long

ll data[4010];
bool out[4010];

int main(){
  int i,j,k,n;

  while(scanf("%d",&n)){
    if(n == 0) break;
    ll a, b;
    int id;
    vector<int> ids;
    bool f = false;

    rep(i,4010) data[i] = 0;
    rep(i,4010) out[i] = false;

    while(n--){
      scanf("%d %lld %lld",&id,&a,&b);

      ids.push_back(id);
      data[id] += a * b;
      if(data[id] >= 1000000LL) out[id] = true;
    }

    rep(i,ids.size()) if(out[ids[i]]){
      printf("%d\n",ids[i]);
      out[ids[i]] = false;
      f = true;
    }
    if(f) puts("NO");
  }

  return 0;
}

C++: #include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;
int main()
{
	while(1)
	{
		int n; cin >> n ;
		if(!n) break;
		map<int,long long> a;
		vector<int> ans;
		queue<int> q;
		for(int i=0;i<n;i++)
		{
			long b,c; int num;
			cin >> num >> b	>> c ;
			a[num]+=(long long) b*c;
			bool flag=true;
			for(int j=0;j<q.size();j++)
			{
				int tmp=q.front();
				if(tmp==num) flag=false;
				q.push(tmp); q.pop();
			}
			if(flag==true) q.push(num);
		}
		map<int,long long>::iterator p;
		bool flag=false;
		for(p=a.begin(); p!=a.end();p++)
			if(p->second >= 1000000) {ans.push_back(p->first); flag=true;}
		if(flag==false) cout << "NA" << endl;
		else
		{
			while(!q.empty() && !ans.empty())
			{
				vector<int>::iterator p;
				int tmp=q.front(); q.pop();
				p=find(ans.begin(),ans.end(),tmp);
				if(p!=ans.end()) cout << *p << endl;
			}
		}
	}
}

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

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define IN(a, b, x) (a<=x&&x<b)
#define MP make_pair
#define PB push_back
#define INF (1LL<<30)
#define LLINF (1LL<<60)
#define PI 3.14159265359
#define EPS 1e-12
//#define int ll

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }

int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};

ll cost[4010];
signed main(void)
{
  while(true) {
    int n;
    cin >> n;
    if(!n) break;
    VI v;
    REP(i, n) {
      ll e, p, q;
      cin >> e >> p >> q;
      if(cost[e] < 1000000 && cost[e]+p*q>=1000000) {
        v.PB(e);
        cost[e] = 1000000;
      } else {
        cost[e] += p*q;
      }
    }
    if(v.size() == 0) cout << "NA" << endl;
    REP(i, v.size()) cout << v[i] << endl;
  }

  return 0;
}

C++: #include<iostream>
#include<string>
using namespace std;
int main(){
	int n,s[5000];
	int a,b,c;
	while(true){
	cin>>n;
	if(n==0)
		break;
	for(int i=0;i<5000;i++)
		s[i]=0;
	for(int i=0;i<n;i++){
		cin>>a>>b>>c;
		s[a]+=b*c;
	}
	bool t=false;
	for(int i=0;i<5000;i++){
		if(s[i]>=1000000){
			cout<<i<<endl;
			t=true;
		}
	}
	if(t==false)
		cout<<"NA"<<endl;
	}
	return 0;
}