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 <iostream>
using namespace std;

int main(){
    while(1){
        long long sale[4001], a, b, c, i, j, n;
        int k = 0;
        cin >> n;
        if(n == 0)break;
        for(i = 0; i < 4001; i++){
            sale[i] = 0;
        }
        for(i = 0; i < n; i++){
            cin >> a >> b >> c;
            if(sale[a] >= 0){
                sale[a] += b*c;
                if(sale[a] >= 1000000){
                    cout << a << endl;
                    sale[a] = -1;
                    k++;
                }
            }
        }
        if(k == 0){
            cout << "NA" << endl;
        }
    }
    return 0;
}

C++: #include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
using namespace std;
typedef long long ll;
int main() {
    int n;
    while (cin >> n && n) {
        unordered_map<int, int> pos;
        vector<pair<int, ll>> res(4001);
        for (int i=1; i<=n; ++i) {
            int no;
            ll price, quantity;
            cin >> no >> price >> quantity;
            if ( ! pos[no]) {
                pos[no] = i;
                res[pos[no]].first = no;
            }
            res[pos[no]].second += price * quantity;
        }

        bool NA = true;
        for (int i=0; i<(int)res.size(); ++i) {
            if (res[i].second >= 1000000) {
                cout << res[i].first << endl;
                NA = false;
            }
        }
        if (NA)
            cout << "NA" << endl;
    }
    return 0;
}

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

int main(){
	int N;
	
	while(cin>>N,N){
		map<int,long long int> mp;
		vector <int> vi;
		int cnt=0;
		for(int i=0;i<N;i++){
			long long int num,tanka,suuryo;
			cin>>num>>tanka>>suuryo;
			if(mp[num]==0){
				vi.push_back(num);
			}
			mp[num]+=tanka*suuryo;
		}
		vector<int>::iterator it=vi.begin();
		for(;it!=vi.end();it++){
			if(mp[*it]>=1000000){
				cout<<*it<<endl;
				cnt++;
			}
		}
		if(cnt==0){
			cout<<"NA"<<endl;
		}
	}
	return 0;
}

C++: #include <stdio.h>
#include <map>
#include <set>

using namespace std;

int main(){
	while(1){
		int n;
		scanf("%d", &n);
		if(n==0){
			puts("NA");
			break;
		}

		map<int,int> m;
		map<int,int>::iterator it;
		set<int> v;
		int a,b,c;
		for(int i=0;i<n;i++){
			scanf("%d%d%d", &a,&b,&c);
			if((it=m.find(a)) != m.end()){
				m[a] += b*c;
			}else {
				m.insert(pair<int,int>(a,b*c));
			}

			if(m[a] >= 1000000 && v.find(a) == v.end()){
				printf("%d\n", a);
				v.insert(a);
			}
		}
	}
}

C++: #include<bits/stdc++.h>
using namespace std;
int main(){
  int n,num,flag=0,flag2=0;
  long long tanka,sell;
  while(cin>>n,n!=0){
    flag=0;flag2=0;
    vector<int> nu;
    vector<int> vi;
    vector<pair<int,long long> > pii;
    for(int i=0;i<n;i++){
      cin>>num>>tanka>>sell;
      for(int j=0;j<vi.size();j++){
	if(num==vi[j]){
	  flag2=1;
	  break;
	}
      }
      if(flag2==0){
	flag=0;
	for(int j=0;j<pii.size();j++){
	  if(pii[j].first==num){
	    flag=1;
	    pii.push_back(make_pair(num,((tanka*sell)+pii[j].second)));
	    if(((tanka*sell)+pii[i].second)>=1000000)
	      vi.push_back(num);
	    break;
	  }
	}
	if(flag==0){
	  nu.push_back(num);
	  pii.push_back(make_pair(num,tanka*sell));
	  if(tanka*sell>=1000000)
	    vi.push_back(num);
	}
      }
    }
    if(vi.empty())
      cout<<"NA"<<endl;
    else{
      for(int k=0;k<nu.size();k++){
	for(int l=0;l<vi.size();l++){
	  if(nu[k]==vi[l])
	    cout<<nu[k]<<endl;
	}
      }
    }
  }
  return 0;
}

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

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

typedef long long ll;
typedef queue<int> qi;

const int lim = 1000000;

int main()
{
    int n; ll en, price, qty; qi que;
    while(cin >> n && n) {
        if (n == 0) break;

        int check[4001] = {0};

        for(int i=0; i < n; ++i) {
            cin >> en >> price >> qty;

            if (check[en] >= 0) {
                check[en] += price*qty;
            }

            if (check[en] >= lim) {
                que.push(en);
                check[en]=-1;
            }
        }

        if (que.empty()) {
            cout << "NA" << endl;
        } else {
            for(int i=0,len=que.size(); i < len; ++i) {
                cout << que.front() << endl;
                que.pop();
            }
        }
    }

    return 0;
}

C++: #include "bits/stdc++.h"

#define REP(i,num) for(int i=0;i<(num);++i)
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

class Data{
public:
	int N{-1},E;
	ll S;
	bool operator<(const Data& r){
		return N<r.N;
	}
};

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	while(true){
		int N=in();
		if(!N) break;
		map<int,Data> H;
		REP(i,N){
			int E=in();
			ll P=in<ll>(),Q=in<ll>();
			H[E].S+=P*Q;
			H[E].E=E;
			if(H[E].N==-1) H[E].N=i;
		}
		vector<Data> D;
		for(auto& x:H) D.push_back(x.second);
		sort(ALL(D));
		int num=0;
		for(auto& x:D){
			if(x.S>=1000000LL){
				out(x.E);
				num++;
			}
		}
		if(!num) out("NA");
	}
	
	return 0;
}