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 <bits/stdc++.h>
using namespace std;
#define int long long



signed main(){
  while(true){
    int n;cin >> n;
    if(n == 0)break;
    
    // mp[e].first: 社員番号
    // mp[e].second.first: 売上の合計
    // mp[e].second.second: 入力に最初に入ったときの順番
    map<int, pair<int, int>> mp;
    for(int i = 0;i < n;i++){
      int e, p, q;cin >> e >> p >> q;
      if(mp.find(e) == mp.end()){
        mp[e] = make_pair(p*q, i);  // 一回目の処理
      }else{
        mp[e] = make_pair(mp[e].first+p*q, mp[e].second); // 二回目以降の処理
      }
    }
    
    // 条件を満たす社員をソートするためのvector
    // vec[i].first: 入力に最初に入ったときの順番
    // vec[i].second: 社員番号
    vector<pair<int, int>> vec;
    for(auto x: mp)if(x.second.first >= 1000000){
      vec.push_back(make_pair(x.second.second, x.first)); // 条件を満たす社員を追加
    }
    sort(vec.begin(), vec.end()); // ソート実行
    
    if(vec.size() == 0){
      cout << "NA" << endl;   // 該当する社員がいなかった時
      continue;
    }
    for(int i = 0;i < vec.size();i++){
      cout << vec[i].second << endl; // 社員出力
    }
  }
  return 0;
}

C++: #include<iostream>
#include<iomanip>
#include<algorithm>
#include<array>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<functional>
#include<limits>
#include<list>
#include<map>
#include<numeric>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<unordered_map>
#include<queue>
#include<vector>
using namespace std;

#define int long long
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define dump(o) {cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) {cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
const int MOD = 1e9 + 7;

signed main() {
	int E[4010] = {};
	for (int n; cin >> n&&n;) {
		memset(E, 0, sizeof(E));
		rep(i, 0, n) {
			int e, p, q; cin >> e >> p >> q;
			E[e] += p*q;
		}
		bool flag = true;
		rep(i, 0, 4010) {
			if (E[i] >= 1000000) {
				flag = false;
				cout << i << endl;
			}
		}
		if (flag)cout << "NA" << endl;
	}
	return 0;
}

C++:  #include<iostream>
 #include<stdio.h>
 #include<string>
 #include<math.h>
 #include<iomanip>
 #include<algorithm>
 #include<string.h>
 #include<cctype>
 #include<map>
 #include<set>
 #include<vector>
 #include<sstream>
 #include<stack>
 #include<queue>
 
 using namespace std;
 
 int main()
 {
   int n;
   while(cin>>n&&n)
   {
     map<int,long long int> mm;
     bool flag=false;
     for(int i=0;i<n;i++)
     {
       int id,p,q;
       cin>>id>>p>>q;
       mm[id]+=(p*q);        
     }           
     map<int,long long int>::iterator iter;
     for(iter=mm.begin();iter!=mm.end();++iter)
     {
       if((iter->second)>=1000000)
       {
         cout<<(iter->first)<<endl;        
         flag=true;
       }                                  
     }
     if(!flag) cout<<"NA"<<endl;
   }
   //while(1);
   return 0;
 }

C++: #define _USE_MATH_DEFINES
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>

using namespace std;

typedef long long ll;
typedef pair<double,double> P;

int main(){
	
	int num;
	vector<int> order;
	while(~scanf("%d",&num)){
		if(num==0) break;
		bool isok=false;
		map<int,ll> val;		
		for(int i=0;i<num;i++){
			int n;
			ll p,q;
			scanf("%d %lld %lld",&n,&p,&q);
			val[n] += p*q;
			if(find(order.begin(),order.end(),n) == order.end()){
				order.push_back(n);
			}
		}

		for(vector<int>::iterator it = order.begin(); it != order.end(); it++){
			if(val[*it] >= 1000000){
				cout << *it << endl;
				isok=true;
			}
		}
		if(!isok) cout <<  "NA" << endl;
	}
}

C++: #include <bits/stdc++.h>
using namespace std ;

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using dict = map<string,int>;
using pii = pair<ll,ll> ;

constexpr int imax = ((1<<30)-1)*2+1 ;
constexpr int inf = 100000000;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0};
const int dx[] = {0,-1,0,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

template<typename T>
void Unique(vector<T> &v){
  sort(all(v));
  v.erase(unique(all(v)),v.end());
}

template<typename T>
T ston(string& str, T n){
  istringstream sin(str) ;
  T num ;
  sin >> num ;
  return num ;
}

void Ans(bool f){
  if(f) cout << "YES"<<endl;
  else cout << "NO"<<endl;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n,a,b,c;
  while(cin >> n){
    if(n == 0) break;
    set<int> s;
    vary(pii,v,4001,make_pair(0,0));
    vary(ll,v2,4001,0);
    int cnt=0;
    rep(i,n){
      cin >> a >> b >> c;
      if(s.insert(a).se){
        ++cnt;
        v[a].se = cnt;
        v[a].fi = a;
      }
      if(v2[a] < 1000000)
        v2[a] += b * c;
    }
    sort(all(v),[](const pii &p,const pii &p2){return p.se < p2.se;});
    bool f = false;
    REP(i,1,4001){
      if(v2[v[i].fi] >= 1000000){
        cout << v[i].fi<<endl;
        f = true;
      }
    }
    if(!f) cout << "NA"<<endl;
  }
  return 0;
}